@@ -52,7 +52,6 @@ import Data.Foldable
52
52
import qualified Data.IntMap.Strict as IntMap
53
53
import Data.IntMap.Strict (IntMap )
54
54
import Data.List
55
- import Data.Ord
56
55
import qualified Data.Set as Set
57
56
import qualified Data.Text as T
58
57
import Development.IDE.GHC.Error
@@ -76,6 +75,8 @@ import Data.ByteString (ByteString)
76
75
import Control.Concurrent.Async (concurrently )
77
76
78
77
import Control.Monad.State
78
+ import System.IO.Error (isDoesNotExistError )
79
+ import Control.Exception.Safe (IOException , catch )
79
80
80
81
-- | This is useful for rules to convert rules that can only produce errors or
81
82
-- a result into the more general IdeResult type that supports producing
@@ -136,22 +137,24 @@ getHieFile file mod = do
136
137
_ -> getPackageHieFile mod file
137
138
138
139
139
- getHomeHieFile :: NormalizedFilePath -> Action ([a ], Maybe HieFile )
140
+ getHomeHieFile :: NormalizedFilePath -> Action ([IOException ], Maybe HieFile )
140
141
getHomeHieFile f = do
141
142
ms <- use_ GetModSummary f
142
- let normal_hie_f = toNormalizedFilePath' hie_f
143
- hie_f = ml_hie_file $ ms_location ms
144
- mbHieTimestamp <- use GetModificationTime normal_hie_f
145
- srcTimestamp <- use_ GetModificationTime f
146
- let isUpToDate
147
- | Just d <- mbHieTimestamp = comparing modificationTime d srcTimestamp == GT
148
- | otherwise = False
149
143
150
- unless isUpToDate $
151
- void $ use_ TypeCheck f
152
-
153
- hf <- liftIO $ whenMaybe isUpToDate (loadHieFile hie_f)
154
- return ([] , hf)
144
+ -- .hi and .hie files are generated as a byproduct of typechecking.
145
+ -- To avoid duplicating staleness checking already performed for .hi files,
146
+ -- we overapproximate here by depending on the GetModIface rule.
147
+ hiFile <- use GetModIface f
148
+
149
+ case hiFile of
150
+ Nothing -> return ([] , Nothing )
151
+ Just _ -> liftIO $ do
152
+ hf <- loadHieFile $ ml_hie_file $ ms_location ms
153
+ return ([] , Just hf)
154
+ `catch` \ e ->
155
+ if isDoesNotExistError e
156
+ then return ([] , Nothing )
157
+ else return ([e], Nothing )
155
158
156
159
getPackageHieFile :: Module -- ^ Package Module to load .hie file for
157
160
-> NormalizedFilePath -- ^ Path of home module importing the package module
@@ -575,26 +578,24 @@ getHiFileRule = defineEarlyCutoff $ \GetHiFile f -> do
575
578
case sequence depHis of
576
579
Nothing -> pure (Nothing , ([] , Nothing ))
577
580
Just deps -> do
578
- gotHiFile <- getFileExists hiFile
579
- if not gotHiFile
580
- then pure (Nothing , ([] , Nothing ))
581
- else do
582
- hiVersion <- use_ GetModificationTime hiFile
583
- modVersion <- use_ GetModificationTime f
584
- let sourceModified = modificationTime hiVersion < modificationTime modVersion
585
- if sourceModified
586
- then do
581
+ mbHiVersion <- use GetModificationTime hiFile
582
+ modVersion <- use_ GetModificationTime f
583
+ case (mbHiVersion, modVersion) of
584
+ (Just hiVersion, ModificationTime {})
585
+ | modificationTime hiVersion >= modificationTime modVersion -> do
586
+ session <- hscEnv <$> use_ GhcSession f
587
+ r <- liftIO $ loadInterface session ms deps
588
+ case r of
589
+ Right iface -> do
590
+ let result = HiFileResult ms iface
591
+ return (Just (fingerprintToBS (getModuleHash iface)), ([] , Just result))
592
+ Left err -> do
593
+ let diag = ideErrorWithSource (Just " interface file loading" ) (Just DsError ) f . T. pack $ err
594
+ return (Nothing , (pure diag, Nothing ))
595
+ (_, VFSVersion {}) ->
596
+ error " internal error - GetHiFile of file of interest"
597
+ _ ->
587
598
pure (Nothing , ([] , Nothing ))
588
- else do
589
- session <- hscEnv <$> use_ GhcSession f
590
- r <- liftIO $ loadInterface session ms deps
591
- case r of
592
- Right iface -> do
593
- let result = HiFileResult ms iface
594
- return (Just (fingerprintToBS (getModuleHash iface)), ([] , Just result))
595
- Left err -> do
596
- let diag = ideErrorWithSource (Just " interface file loading" ) (Just DsError ) f . T. pack $ err
597
- return (Nothing , (pure diag, Nothing ))
598
599
599
600
getModSummaryRule :: Rules ()
600
601
getModSummaryRule = define $ \ GetModSummary f -> do
0 commit comments