Skip to content

Commit 515f90c

Browse files
committed
Revert "Check if dependency HIE files already indexed"
This reverts commit 096c52b.
1 parent 25addfb commit 515f90c

File tree

4 files changed

+15
-40
lines changed

4 files changed

+15
-40
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module Development.IDE.Core.Compile
2121
, generateByteCode
2222
, generateHieAsts
2323
, writeAndIndexHieFile
24-
, HieDbModuleQuery(..)
2524
, indexHieFile
2625
, writeHiFile
2726
, getModSummaryFromImports
@@ -860,10 +859,6 @@ spliceExpressions Splices{..} =
860859
, DL.fromList $ map fst awSplices
861860
]
862861

863-
data HieDbModuleQuery
864-
= HieDbModuleQuery ModuleName Unit
865-
| DontCheckForModule
866-
867862
-- | In addition to indexing the `.hie` file, this function is responsible for
868863
-- maintaining the 'IndexQueue' state and notifying the user about indexing
869864
-- progress.
@@ -892,14 +887,16 @@ data HieDbModuleQuery
892887
-- TVar to 0 in order to set it up for a fresh indexing session. Otherwise, we
893888
-- can just increment the 'indexCompleted' TVar and exit.
894889
--
895-
indexHieFile :: ShakeExtras -> HieDbModuleQuery -> NormalizedFilePath -> HieDb.SourceFile -> Util.Fingerprint -> Compat.HieFile -> IO ()
896-
indexHieFile se query hiePath sourceFile !hash hf = do
890+
indexHieFile :: ShakeExtras -> NormalizedFilePath -> HieDb.SourceFile -> Util.Fingerprint -> Compat.HieFile -> IO ()
891+
indexHieFile se hiePath sourceFile !hash hf = do
897892
IdeOptions{optProgressStyle} <- getIdeOptionsIO se
898893
atomically $ do
899894
pending <- readTVar indexPending
900895
case HashMap.lookup hiePath pending of
901896
Just pendingHash | pendingHash == hash -> pure () -- An index is already scheduled
902897
_ -> do
898+
-- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
899+
let !hf' = hf{hie_hs_src = mempty}
903900
modifyTVar' indexPending $ HashMap.insert hiePath hash
904901
writeTQueue indexQueue $ \withHieDb -> do
905902
-- We are now in the worker thread
@@ -914,24 +911,8 @@ indexHieFile se query hiePath sourceFile !hash hf = do
914911
-- Using bracket, so even if an exception happen during withHieDb call,
915912
-- the `post` (which clean the progress indicator) will still be called.
916913
bracket_ (pre optProgressStyle) post $
917-
withHieDb indexIfNotAlready
914+
withHieDb (\db -> HieDb.addRefsFromLoaded db (fromNormalizedFilePath hiePath) sourceFile hash hf')
918915
where
919-
-- hiedb doesn't use the Haskell src, so we clear it to avoid unnecessarily keeping it around
920-
hf' :: Compat.HieFile
921-
!hf' = hf{hie_hs_src = mempty}
922-
indexIfNotAlready :: HieDb -> IO ()
923-
indexIfNotAlready db = case query of
924-
DontCheckForModule -> doIndexing
925-
HieDbModuleQuery moduleName unit -> do
926-
mRow <- HieDb.lookupHieFile db moduleName unit
927-
case mRow of
928-
Nothing -> doIndexing
929-
Just _row -> return ()
930-
where
931-
doIndexing :: IO ()
932-
doIndexing =
933-
HieDb.addRefsFromLoaded db (fromNormalizedFilePath hiePath) sourceFile hash hf'
934-
935916
HieDbWriter{..} = hiedbWriter se
936917

937918
-- Get a progress token to report progress and update it for the current file
@@ -1024,7 +1005,7 @@ writeAndIndexHieFile hscEnv se mod_summary srcPath exports ast source =
10241005
GHC.mkHieFile' mod_summary exports ast source
10251006
atomicFileWrite se targetPath $ flip GHC.writeHieFile hf
10261007
hash <- Util.getFileHash targetPath
1027-
indexHieFile se DontCheckForModule (toNormalizedFilePath' targetPath) (HieDb.RealFile $ fromNormalizedFilePath srcPath) hash hf
1008+
indexHieFile se (toNormalizedFilePath' targetPath) (HieDb.RealFile $ fromNormalizedFilePath srcPath) hash hf
10281009
where
10291010
dflags = hsc_dflags hscEnv
10301011
mod_location = ms_location mod_summary

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ getModIfaceFromDiskAndIndexRule recorder =
894894
-- can just re-index the file we read from disk
895895
Right hf -> liftIO $ do
896896
logWith recorder Logger.Debug $ LogReindexingHieFile f
897-
indexHieFile se DontCheckForModule (toNormalizedFilePath' hie_loc) (HieDb.RealFile $ fromNormalizedFilePath f) hash hf
897+
indexHieFile se (toNormalizedFilePath' hie_loc) (HieDb.RealFile $ fromNormalizedFilePath f) hash hf
898898

899899
return (Just x)
900900

ghcide/src/Development/IDE/GHC/Compat/Units.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module Development.IDE.GHC.Compat.Units (
2727
unitHiddenModules,
2828
unitLibraryDirs,
2929
UnitInfo.unitId,
30-
UnitInfo.mkUnit,
3130
unitDepends,
3231
unitHaddockInterfaces,
3332
unitInfoId,
@@ -126,6 +125,7 @@ type PreloadUnitClosure = ()
126125
type Unit = UnitId
127126
#endif
128127

128+
129129
#if !MIN_VERSION_ghc(9,0,0)
130130
unitString :: Unit -> String
131131
unitString = Module.unitIdString

ghcide/src/Development/IDE/Types/HscEnvEq.hs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import qualified Data.Set as Set
3030
import qualified Data.Text as T
3131
import Data.Unique (Unique)
3232
import qualified Data.Unique as Unique
33-
import Development.IDE.Core.Compile (HieDbModuleQuery(HieDbModuleQuery), indexHieFile, loadHieFile)
33+
import Development.IDE.Core.Compile (indexHieFile, loadHieFile)
3434
import Development.IDE.Core.Shake (HieDbWriter(indexQueue), ShakeExtras(hiedbWriter, ideNc, logger, lspEnv), mkUpdater)
3535
import Development.IDE.GHC.Compat
3636
import qualified Development.IDE.GHC.Compat.Util as Maybes
@@ -146,25 +146,19 @@ newHscEnvEqWithImportPaths envImportPaths se hscEnv deps = do
146146
(libraryDir : _) -> libraryDir
147147
hieDir :: FilePath
148148
hieDir = pkgLibDir </> "extra-compilation-artifacts"
149-
packageUnit :: Unit
150-
packageUnit = mkUnit package
151149
modIfaces <- mapMaybeM loadModIface modules
152-
traverse_ (indexModuleHieFile hieDir packageUnit) modIfaces
153-
indexModuleHieFile :: FilePath -> Unit -> ModIface -> IO ()
154-
indexModuleHieFile hieDir packageUnit modIface = do
155-
let modName :: ModuleName
156-
modName = moduleName $ mi_module modIface
157-
hiePath :: FilePath
158-
hiePath = hieDir </> toFilePath modName ++ ".hie"
159-
query :: HieDbModuleQuery
160-
query = HieDbModuleQuery modName packageUnit
150+
traverse_ (indexModuleHieFile hieDir) modIfaces
151+
indexModuleHieFile :: FilePath -> ModIface -> IO ()
152+
indexModuleHieFile hieDir modIface = do
153+
let hiePath :: FilePath
154+
hiePath = hieDir </> toFilePath (moduleName $ mi_module modIface) ++ ".hie"
161155
hieResults <- tryAny $ loadHieFile (mkUpdater $ ideNc se) hiePath
162156
case hieResults of
163157
Left e -> Logger.logDebug (logger se) $
164158
"Failed to index dependency HIE file:\n"
165159
<> T.pack (show e)
166160
Right hie ->
167-
indexHieFile se query (toNormalizedFilePath' hiePath) (FakeFile Nothing) (mi_src_hash modIface) hie
161+
indexHieFile se (toNormalizedFilePath' hiePath) (FakeFile Nothing) (mi_src_hash modIface) hie
168162
toFilePath :: ModuleName -> FilePath
169163
toFilePath = separateDirectories . prettyModuleName
170164
where

0 commit comments

Comments
 (0)