Skip to content

Commit

Permalink
Prefer non-boot files when creating the FinderCache. (#3687)
Browse files Browse the repository at this point in the history
Boot files in the finder cache can lead to uneccesary linking errors like
https://gitlab.haskell.org/ghc/ghc/-/issues/19816 when we actually have a
non-boot file in scope.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
wz1000 and mergify[bot] authored Jul 25, 2023
1 parent 5aa14b3 commit 7a2b9a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
#if MIN_VERSION_ghc(9,3,0)
-- TODO: support backpack
nodeKeyToInstalledModule :: NodeKey -> Maybe InstalledModule
-- We shouldn't get boot files here, but to be safe, never map them to an installed module
-- because boot files don't have linkables we can load, and we will fail if we try to look
-- for them
nodeKeyToInstalledModule (NodeKey_Module (ModNodeKeyWithUid (GWIB mod IsBoot) uid)) = Nothing
nodeKeyToInstalledModule (NodeKey_Module (ModNodeKeyWithUid (GWIB mod _) uid)) = Just $ mkModule uid mod
nodeKeyToInstalledModule _ = Nothing
moduleToNodeKey :: Module -> NodeKey
Expand Down Expand Up @@ -1073,11 +1077,18 @@ mergeEnvs env (ms, deps) extraMods envs = do
combineModules a b
| HsSrcFile <- mi_hsc_src (hm_iface a) = a
| otherwise = b

-- Prefer non-boot files over non-boot files
-- otherwise we can get errors like https://gitlab.haskell.org/ghc/ghc/-/issues/19816
-- if a boot file shadows over a non-boot file
combineModuleLocations a@(InstalledFound ml m) b | Just fp <- ml_hs_file ml, not ("boot" `isSuffixOf` fp) = a
combineModuleLocations _ b = b

concatFC :: FinderCacheState -> [FinderCache] -> IO FinderCache
concatFC cur xs = do
fcModules <- mapM (readIORef . fcModuleCache) xs
fcFiles <- mapM (readIORef . fcFileCache) xs
fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv const) cur fcModules
fcModules' <- newIORef $! foldl' (plusInstalledModuleEnv combineModuleLocations) cur fcModules
fcFiles' <- newIORef $! Map.unions fcFiles
pure $ FinderCache fcModules' fcFiles'

Expand Down

0 comments on commit 7a2b9a1

Please sign in to comment.