on master help sign in
Change the representation of filestamps (#415)

* Change the representation of filestamps This is needed to be able to compare them, which we want to use for loading .hie and .hi files * Update src/Development/IDE/Core/FileStore.hs Co-Authored-By: Neil Mitchell <ndmitchell@gmail.com> Co-authored-by: Neil Mitchell <ndmitchell@gmail.com>

commiteb69b815aac257345b33bd8f979b5035dced6486 authorPepe Iborra <pepeiborra@gmail.com> dateTue 11 Feb 2020, 09:43 (7 years ago) parent64f6c6a
2 files changed+18−12
src/Development/IDE/Core/FileStore.hs+8−5 src/Development/IDE/Core/Shake.hs+10−7
src/Development/IDE/Core/FileStore.hs+8−5
@@ -95,11 +95,12 @@ getModificationTimeRule :: VFSHandle -> Rules ()
9595getModificationTimeRule vfs =
9696 defineEarlyCutoff $ \GetModificationTime file -> do
9797 let file' = fromNormalizedFilePath file
98− let wrap time = (Just time, ([], Just $ ModificationTime time))
98+ let wrap time@(l,s) = (Just $ BS.pack $ show time, ([], Just $ ModificationTime l s))
9999 alwaysRerun
100100 mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file
101101 case mbVirtual of
102− Just (virtualFileVersion -> ver) -> pure (Just $ BS.pack $ show ver, ([], Just $ VFSVersion ver))
102+ Just (virtualFileVersion -> ver) ->
103+ pure (Just $ BS.pack $ show ver, ([], Just $ VFSVersion ver))
103104 Nothing -> liftIO $ fmap wrap (getModTime file')
104105 `catch` \(e :: IOException) -> do
105106 let err | isDoesNotExistError e = "File does not exist: " ++ file'
@@ -115,11 +116,13 @@ getModificationTimeRule vfs =
115116 -- We might also want to try speeding this up on Windows at some point.
116117 -- TODO leverage DidChangeWatchedFile lsp notifications on clients that
117118 -- support them, as done for GetFileExists
118− getModTime :: FilePath -> IO BS.ByteString
119+ getModTime :: FilePath -> IO (Int,Int)
119120 getModTime f =
120121#ifdef mingw32_HOST_OS
121122 do time <- Dir.getModificationTime f
122− pure $! BS.pack $ show (toModifiedJulianDay $ utctDay time, diffTimeToPicoseconds $ utctDayTime time)
123+ let !day = toModifiedJulianDay $ utctDay time
124+ !dayTime = diffTimeToPicoseconds $ utctDayTime time
125+ pure (day, dayTime)
123126#else
124127 withCString f $ \f' ->
125128 alloca $ \secPtr ->
@@ -127,7 +130,7 @@ getModificationTimeRule vfs =
127130 Posix.throwErrnoPathIfMinus1Retry_ "getmodtime" f $ c_getModTime f' secPtr nsecPtr
128131 sec <- peek secPtr
129132 nsec <- peek nsecPtr
130− pure $! BS.pack $ show sec <> "." <> show nsec
133+ pure (fromEnum sec, fromIntegral nsec)
131134
132135-- Sadly even unix’s getFileStatus + modificationTimeHiRes is still about twice as slow
133136-- as doing the FFI call ourselves :(.
src/Development/IDE/Core/Shake.hs+10−7
@@ -36,7 +36,7 @@ module Development.IDE.Core.Shake(
3636 sendEvent,
3737 ideLogger,
3838 actionLogger,
39− FileVersion(..),
39+ FileVersion(..), modificationTime,
4040 Priority(..),
4141 updatePositionMapping,
4242 deleteValue,
@@ -762,19 +762,22 @@ instance Binary GetModificationTime
762762-- | Get the modification time of a file.
763763type instance RuleResult GetModificationTime = FileVersion
764764
765−-- | We store the modification time as a ByteString since we need
766−-- a ByteString anyway for Shake and we do not care about how times
767−-- are represented.
768−data FileVersion = VFSVersion Int | ModificationTime BS.ByteString
765+data FileVersion
766+ = VFSVersion Int
767+ | ModificationTime
768+ !Int -- ^ Large unit (platform dependent, do not make assumptions)
769+ !Int -- ^ Small unit (platform dependent, do not make assumptions)
769770 deriving (Show, Generic)
770771
771772instance NFData FileVersion
772773
773774vfsVersion :: FileVersion -> Maybe Int
774775vfsVersion (VFSVersion i) = Just i
775−vfsVersion (ModificationTime _) = Nothing
776−
776+vfsVersion ModificationTime{} = Nothing
777777
778+modificationTime :: FileVersion -> Maybe (Int, Int)
779+modificationTime VFSVersion{} = Nothing
780+modificationTime (ModificationTime large small) = Just (large, small)
778781
779782getDiagnosticsFromStore :: StoreItem -> [Diagnostic]
780783getDiagnosticsFromStore (StoreItem _ diags) = concatMap SL.fromSortedList $ Map.elems diags