Skip to content

Commit a767490

Browse files
committed
cope with lookupCache function for module location
1 parent 03f6b3c commit a767490

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ typecheckModule (IdeDefer defer) hsc tc_helpers pm = do
207207
where
208208
demoteIfDefer = if defer then demoteTypeErrorsToWarnings else id
209209

210+
lookupCache :: HscEnv -> InstalledModule -> IO (Maybe InstalledFindResult)
211+
lookupCache hsc_env installedMod = do
212+
#if MIN_VERSION_ghc(9,11,0)
213+
lookupFinderCache (hsc_FC hsc_env) installedMod
214+
#else
215+
; moduleLocs <- readIORef (fcModuleCache $ hsc_FC hsc_env)
216+
; return $ lookupInstalledModuleEnv moduleLocs installedMod
217+
#endif
218+
210219
-- | Install hooks to capture the splices as well as the runtime module dependencies
211220
captureSplicesAndDeps :: TypecheckHelpers -> HscEnv -> (HscEnv -> IO a) -> IO (a, Splices, ModuleEnv BS.ByteString)
212221
captureSplicesAndDeps TypecheckHelpers{..} env k = do
@@ -294,14 +303,17 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
294303
mods_transitive_list =
295304
mapMaybe nodeKeyToInstalledModule $ Set.toList mods_transitive
296305

297-
-- todo: 9.12
298-
; moduleLocs <- readIORef (fcModuleCache $ hsc_FC hsc_env)
299-
; lbs <- getLinkables [toNormalizedFilePath' file
306+
-- todo: 9.12 this is inefficient
307+
308+
; lbs <- getLinkables =<<
309+
sequence
310+
[toNormalizedFilePath' <$> file
300311
| installedMod <- mods_transitive_list
301-
, let ifr = fromJust $ lookupInstalledModuleEnv moduleLocs installedMod
302-
file = case ifr of
303-
InstalledFound loc _ ->
304-
fromJust $ ml_hs_file loc
312+
, let file :: IO FilePath
313+
file = do
314+
ifr'<- lookupCache hsc_env installedMod
315+
case ifr' of
316+
Just (InstalledFound loc _) | Just l <- ml_hs_file loc -> return l
305317
_ -> panic "hscCompileCoreExprHook: module not found"
306318
]
307319
; let hsc_env' = loadModulesHome (map linkableHomeMod lbs) hsc_env
@@ -920,14 +932,19 @@ handleGenerationErrors' dflags source action =
920932
-- transitive dependencies will be contained in envs)
921933
mergeEnvs :: HscEnv -> ModuleGraph -> ModSummary -> [HomeModInfo] -> [HscEnv] -> IO HscEnv
922934
mergeEnvs env mg ms extraMods envs = do
935+
#if !MIN_VERSION_ghc(9,11,0)
923936
let im = Compat.installedModule (toUnitId $ moduleUnit $ ms_mod ms) (moduleName (ms_mod ms))
924937
ifr = InstalledFound (ms_location ms) im
925938
curFinderCache = Compat.extendInstalledModuleEnv Compat.emptyInstalledModuleEnv im ifr
939+
926940
newFinderCache <- concatFC curFinderCache (map hsc_FC envs)
941+
#endif
927942
return $! loadModulesHome extraMods $
928943
let newHug = foldl' mergeHUG (hsc_HUG env) (map hsc_HUG envs) in
929944
(hscUpdateHUG (const newHug) env){
945+
#if !MIN_VERSION_ghc(9,11,0)
930946
hsc_FC = newFinderCache,
947+
#endif
931948
hsc_mod_graph = mg
932949
}
933950

@@ -940,6 +957,7 @@ mergeEnvs env mg ms extraMods envs = do
940957
| HsSrcFile <- mi_hsc_src (hm_iface a) = a
941958
| otherwise = b
942959

960+
#if !MIN_VERSION_ghc(9,11,0)
943961
-- Prefer non-boot files over non-boot files
944962
-- otherwise we can get errors like https://gitlab.haskell.org/ghc/ghc/-/issues/19816
945963
-- if a boot file shadows over a non-boot file
@@ -953,6 +971,7 @@ mergeEnvs env mg ms extraMods envs = do
953971
fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv combineModuleLocations) cur fcModules
954972
fcFiles' <- newIORef $! Map.unions fcFiles
955973
pure $ FinderCache fcModules' fcFiles'
974+
#endif
956975

957976

958977
withBootSuffix :: HscSource -> ModLocation -> ModLocation
@@ -1384,15 +1403,14 @@ parseRuntimeDeps anns = mkModuleEnv $ mapMaybe go anns
13841403
-- See Note [Recompilation avoidance in the presence of TH]
13851404
checkLinkableDependencies :: MonadIO m => HscEnv -> ([NormalizedFilePath] -> m [BS.ByteString]) -> ModuleEnv BS.ByteString -> m (Maybe RecompileRequired)
13861405
checkLinkableDependencies hsc_env get_linkable_hashes runtime_deps = do
1387-
moduleLocs <- liftIO $ readIORef (fcModuleCache $ hsc_FC hsc_env)
13881406
let go (mod, hash) = do
1389-
ifr <- lookupInstalledModuleEnv moduleLocs $ Compat.installedModule (toUnitId $ moduleUnit mod) (moduleName mod)
1407+
ifr <- lookupCache hsc_env $ Compat.installedModule (toUnitId $ moduleUnit mod) (moduleName mod)
13901408
case ifr of
1391-
InstalledFound loc _ -> do
1392-
hs <- ml_hs_file loc
1393-
pure (toNormalizedFilePath' hs,hash)
1394-
_ -> Nothing
1395-
hs_files = mapM go (moduleEnvToList runtime_deps)
1409+
Just (InstalledFound loc _) | Just hs <- ml_hs_file loc ->
1410+
pure $ Just (toNormalizedFilePath' hs,hash)
1411+
_ -> return Nothing
1412+
hs_files' = liftIO $ mapM go (moduleEnvToList runtime_deps)
1413+
hs_files <- fmap sequence hs_files'
13961414
case hs_files of
13971415
Nothing -> error "invalid module graph"
13981416
Just fs -> do

0 commit comments

Comments
 (0)