Skip to content

Commit f32f666

Browse files
wz1000mpickering
andauthored
Use a global namecache to read .hie files (#677)
* Use global NameCache for reading HIE files Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com> * ignore hlint * redundant imports * Use hie files as source of truth for name source spans. Since we started reusing `.hi` files, this exposes a bug where definitions aren't available since a bad source span from the `.hi` file gets put into the NameCache. We rectify by ensuring the span in the NameCache always matches the one from the `.hie` file. This has surfaced because an interaction between the commit which uses `.hi` instead of retypechecking and the change to use the shared global NameCache to read `.hie` files. * Add test for missing definitions Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com>
1 parent 7dc6e26 commit f32f666

File tree

9 files changed

+856
-34
lines changed

9 files changed

+856
-34
lines changed

exe/Main.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ cradleToSessionOpts cradle file = do
203203
-- message about the fact that the file is being ignored.
204204
CradleNone -> return (Left [])
205205

206-
emptyHscEnv :: IO HscEnv
207-
emptyHscEnv = do
206+
emptyHscEnv :: IORef NameCache -> IO HscEnv
207+
emptyHscEnv nc = do
208208
libdir <- getLibdir
209209
env <- runGhc (Just libdir) getSession
210210
initDynLinker env
211-
pure env
211+
pure $ setNameCache nc env
212212

213213
-- | Convert a target to a list of potential absolute paths.
214214
-- A TargetModule can be anywhere listed by the supplied include
@@ -262,7 +262,7 @@ loadSession dir = do
262262
InstallationMismatch{..} ->
263263
return $ returnWithVersion $ \fp -> return (([renderPackageSetupException compileTime fp GhcVersionMismatch{..}], Nothing),[])
264264
InstallationChecked compileTime ghcLibCheck -> return $ do
265-
ShakeExtras{logger, eventer, restartShakeSession, withIndefiniteProgress} <- getShakeExtras
265+
ShakeExtras{logger, eventer, restartShakeSession, withIndefiniteProgress, ideNc} <- getShakeExtras
266266
IdeOptions{optTesting = IdeTesting optTesting} <- getIdeOptions
267267

268268
-- Create a new HscEnv from a hieYaml root and a set of options
@@ -273,7 +273,7 @@ loadSession dir = do
273273
-> IO (HscEnv, ComponentInfo, [ComponentInfo])
274274
packageSetup (hieYaml, cfp, opts) = do
275275
-- Parse DynFlags for the newly discovered component
276-
hscEnv <- emptyHscEnv
276+
hscEnv <- emptyHscEnv ideNc
277277
(df, targets) <- evalGhcEnv hscEnv $
278278
setOptions opts (hsc_dflags hscEnv)
279279
let deps = componentDependencies opts ++ maybeToList hieYaml
@@ -317,9 +317,7 @@ loadSession dir = do
317317
-- It's important to keep the same NameCache though for reasons
318318
-- that I do not fully understand
319319
logInfo logger (T.pack ("Making new HscEnv" ++ show inplace))
320-
hscEnv <- case oldDeps of
321-
Nothing -> emptyHscEnv
322-
Just (old_hsc, _) -> setNameCache (hsc_NC old_hsc) <$> emptyHscEnv
320+
hscEnv <- emptyHscEnv ideNc
323321
newHscEnv <-
324322
-- Add the options for the current component to the HscEnv
325323
evalGhcEnv hscEnv $ do

ghcide.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ library
159159
hs-source-dirs: src-ghc88
160160
other-modules:
161161
Development.IDE.GHC.HieAst
162+
Development.IDE.GHC.HieBin
162163
if (impl(ghc > 8.9))
163164
hs-source-dirs: src-ghc810
164165
other-modules:
165166
Development.IDE.GHC.HieAst
167+
Development.IDE.GHC.HieBin
166168
ghc-options: -Wall -Wno-name-shadowing
167169

168170
executable ghcide-test-preprocessor

0 commit comments

Comments
 (0)