Cheng Shao pushed to branch wip/hi-atomic at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -66,6 +66,7 @@ import GHC.Tc.Utils.Monad
    66 66
     
    
    67 67
     import GHC.Utils.Binary   ( BinData(..) )
    
    68 68
     import GHC.Utils.Error
    
    69
    +import GHC.Utils.Misc
    
    69 70
     import GHC.Utils.Outputable as Outputable
    
    70 71
     import GHC.Utils.Panic
    
    71 72
     import GHC.Utils.Constants (debugIsOn)
    
    ... ... @@ -989,7 +990,8 @@ writeIface :: Logger -> Profile -> CompressionIFace -> FilePath -> ModIface -> I
    989 990
     writeIface logger profile compression_level hi_file_path new_iface
    
    990 991
         = do createDirectoryIfMissing True (takeDirectory hi_file_path)
    
    991 992
              let printer = TraceBinIFace (debugTraceMsg logger 3)
    
    992
    -         writeBinIface profile printer compression_level hi_file_path new_iface
    
    993
    +         withAtomicRename hi_file_path $ \temp_path ->
    
    994
    +           writeBinIface profile printer compression_level temp_path new_iface
    
    993 995
     
    
    994 996
     flagsToIfCompression :: DynFlags -> CompressionIFace
    
    995 997
     flagsToIfCompression dflags
    

  • compiler/GHC/Utils/Misc.hs
    ... ... @@ -133,7 +133,6 @@ import GHC.Stack (HasCallStack)
    133 133
     import GHC.Data.List
    
    134 134
     
    
    135 135
     import Control.Monad    ( guard )
    
    136
    -import Control.Monad.IO.Class ( MonadIO, liftIO )
    
    137 136
     import System.IO.Error as IO ( isDoesNotExistError )
    
    138 137
     import System.Directory ( doesDirectoryExist, getModificationTime, renameFile )
    
    139 138
     import qualified System.Directory.OsPath as OsPath
    
    ... ... @@ -1273,8 +1272,8 @@ fileHashIfExists f =
    1273 1272
     -- and uses their modification time to skip work later,
    
    1274 1273
     -- as otherwise a partially written file (e.g. due to crash or Ctrl+C)
    
    1275 1274
     -- also results in a skip.
    
    1276
    -
    
    1277
    -withAtomicRename :: (MonadIO m) => FilePath -> (FilePath -> m a) -> m a
    
    1275
    +{-# INLINE withAtomicRename #-}
    
    1276
    +withAtomicRename :: FilePath -> (FilePath -> IO ()) -> IO ()
    
    1278 1277
     withAtomicRename targetFile f = do
    
    1279 1278
       -- The temp file must be on the same file system (mount) as the target file
    
    1280 1279
       -- to result in an atomic move on most platforms.
    
    ... ... @@ -1282,9 +1281,8 @@ withAtomicRename targetFile f = do
    1282 1281
       -- This can still be fooled when somebody mounts a different file system
    
    1283 1282
       -- at just the right time, but that is not a case we aim to cover here.
    
    1284 1283
       let temp = targetFile <.> "tmp"
    
    1285
    -  res <- f temp
    
    1286
    -  liftIO $ renameFile temp targetFile
    
    1287
    -  return res
    
    1284
    +  f temp
    
    1285
    +  renameFile temp targetFile
    
    1288 1286
     
    
    1289 1287
     -- --------------------------------------------------------------
    
    1290 1288
     -- split a string at the last character where 'pred' is True,