Skip to content

Commit 9fc2093

Browse files
committed
use modification time rule
1 parent 4c31646 commit 9fc2093

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import Data.HashMap.Strict (HashMap)
109109
import Data.HashSet (HashSet)
110110
import qualified Data.HashSet as Set
111111
import Database.SQLite.Simple
112+
import Development.IDE (Rules, getFileExists)
112113
import Development.IDE.Core.Tracing (withTrace)
113114
import Development.IDE.Session.Diagnostics (renderCradleError)
114115
import Development.IDE.Types.Shake (Key, WithHieDb,
@@ -128,7 +129,6 @@ import qualified Data.Set as OS
128129
import qualified Development.IDE.GHC.Compat.Util as Compat
129130
import GHC.Data.Graph.Directed
130131

131-
import Development.IDE (Rules, getFileExists)
132132
import GHC.Data.Bag
133133
import GHC.Driver.Env (hsc_all_home_unit_ids)
134134
import GHC.Driver.Errors.Types
@@ -541,7 +541,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
541541
hscEnv <- liftIO $ emptyHscEnv ideNc _libDir
542542
all_target_details <- liftIO $ newComponentCache recorder optExtensions hieYaml _cfp hscEnv old_deps new_deps rootDir
543543

544-
this_dep_info <- liftIO $ getDependencyInfo $ maybeToList hieYaml
544+
this_dep_info <- getDependencyInfo $ maybeToList hieYaml
545545
-- this should be added to deps
546546
let (all_targets, this_flags_map, this_options)
547547
= case HM.lookup _cfp flags_map' of
@@ -579,7 +579,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
579579
hscEnv <- liftIO $ emptyHscEnv ideNc libDir
580580
newTargetDfs <- liftIO $ evalGhcEnv hscEnv $ setOptions cfp opts (hsc_dflags hscEnv) rootDir
581581
let deps = componentDependencies opts ++ maybeToList hieYaml
582-
dep_info <- liftIO $ getDependencyInfo deps
582+
dep_info <- getDependencyInfo deps
583583
-- Now lookup to see whether we are combining with an existing HscEnv
584584
-- or making a new one. The lookup returns the HscEnv and a list of
585585
-- information about other components loaded into the HscEnv
@@ -716,7 +716,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
716716
session (hieYaml, cfp, opts, libDir)
717717
-- Failure case, either a cradle error or the none cradle
718718
Left err -> do
719-
dep_info <- liftIO $ getDependencyInfo (maybeToList hieYaml)
719+
dep_info <- getDependencyInfo (maybeToList hieYaml)
720720
let res = (map (\err' -> renderCradleError err' cradle cfp) err, Nothing)
721721
liftIO $ atomically $ modifyTVar' fileToFlags $
722722
Map.insertWith HM.union hieYaml (HM.singleton cfp (res, dep_info))
@@ -741,7 +741,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
741741
Just (opts, old_di) -> do
742742
-- need to differ two kinds of invocation, one is the file is changed
743743
-- other is the cache version bumped
744-
deps_ok <- liftIO $ checkDependencyInfo old_di
744+
deps_ok <- checkDependencyInfo old_di
745745
if not deps_ok
746746
then do
747747
logWith recorder Debug $ LogClearingCache file
@@ -750,15 +750,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
750750
else return $ Just (opts, Map.keys old_di, [], [])
751751
Nothing -> return Nothing
752752
-- install cache version check to get notified when the cache is changed
753-
-- todo but some how it is informing other, then other inform us, causing a loop
753+
v <- useNoFile_ SessionCacheVersion
754+
logWith recorder Debug $ LogCacheVersion file v
755+
754756
case someThing of
755757
Just result@(_, deps, _files, _keys) -> do
756758
mapM_ addDependency deps
757759
return $ Just result
758760
Nothing -> do
759-
v <- useNoFile_ SessionCacheVersion
760-
logWith recorder Debug $ LogCacheVersion file v
761-
762761
catchError file hieYaml $ do
763762
result@(_, deps, files, keys) <- consultCradle file
764763
-- add the deps to the Shake graph
@@ -1128,7 +1127,7 @@ setCacheDirs recorder CacheDirs{..} dflags = do
11281127
-- we can then make a rule to build each entry in the map
11291128

11301129
-- See Note [Multi Cradle Dependency Info]
1131-
type DependencyInfo = Map.Map FilePath (Maybe UTCTime)
1130+
type DependencyInfo = Map.Map FilePath FileVersion
11321131
type HieMap = Map.Map (Maybe FilePath) [RawComponentInfo]
11331132
-- | Maps a "hie.yaml" location to all its Target Filepaths and options.
11341133
type FlagsMap = Map.Map (Maybe FilePath) (HM.HashMap NormalizedFilePath (IdeResult HscEnvEq, DependencyInfo))
@@ -1187,7 +1186,7 @@ data ComponentInfo = ComponentInfo
11871186

11881187
-- | Check if any dependency has been modified lately.
11891188
-- it depend on the last result
1190-
checkDependencyInfo :: DependencyInfo -> IO Bool
1189+
checkDependencyInfo :: DependencyInfo -> Action Bool
11911190
checkDependencyInfo old_di = do
11921191
di <- getDependencyInfo (Map.keys old_di)
11931192
return (di == old_di)
@@ -1202,15 +1201,17 @@ checkDependencyInfo old_di = do
12021201
-- | Computes a mapping from a filepath to its latest modification date.
12031202
-- See Note [Multi Cradle Dependency Info] why we do this ourselves instead
12041203
-- of letting shake take care of it.
1205-
getDependencyInfo :: [FilePath] -> IO DependencyInfo
1204+
getDependencyInfo :: [FilePath] -> Action DependencyInfo
12061205
getDependencyInfo fs = Map.fromList <$> mapM do_one fs
1207-
12081206
where
1209-
safeTryIO :: IO a -> IO (Either IOException a)
1210-
safeTryIO = Safe.try
1211-
1212-
do_one :: FilePath -> IO (FilePath, Maybe UTCTime)
1213-
do_one fp = (fp,) . eitherToMaybe <$> safeTryIO (getModificationTime fp)
1207+
-- safeTryIO :: Action a -> Action (Either IOException a)
1208+
-- safeTryIO = Safe.try
1209+
1210+
do_one :: FilePath -> Action (FilePath, FileVersion)
1211+
do_one fpp = do
1212+
let fp = toNormalizedFilePath' fpp
1213+
fv <- use_ GetModificationTime fp
1214+
return (fromNormalizedFilePath fp, fv)
12141215

12151216
-- | This function removes all the -package flags which refer to packages we
12161217
-- are going to deal with ourselves. For example, if a executable depends

0 commit comments

Comments
 (0)