Skip to content

Commit

Permalink
Some fixes for 9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Nov 22, 2023
1 parent fb934ab commit 5d708f3
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,17 @@ emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
#endif
emptyHscEnv nc libDir = do
-- We call setSessionDynFlags so that the loader is initialised
env <- runGhc (Just libDir) $ getSessionDynFlags >>= setSessionDynFlags >> getSession
-- We need to do this before we call initUnits.
-- However, on GHC 9.2 calling setSessionDynFlags too early
-- can mess up the package db cache for some reason.
-- So on 9.2 the loader is initialised by the call to setSessionDynFlags
-- only after we actually have a proper set of DynFlags
env <- runGhc (Just libDir) $
#if MIN_VERSION_ghc(9,3,0)
getSessionDynFlags >>= setSessionDynFlags >> getSession
#else
getSession
#endif
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)

data TargetDetails = TargetDetails
Expand Down Expand Up @@ -824,20 +834,6 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
#else
do
#endif
-- Whenever we spin up a session on Linux, dynamically load libm.so.6
-- in. We need this in case the binary is statically linked, in which
-- case the interactive session will fail when trying to load
-- ghc-prim, which happens whenever Template Haskell is being
-- evaluated or haskell-language-server's eval plugin tries to run
-- some code. If the binary is dynamically linked, then this will have
-- no effect.
-- See https://github.com/haskell/haskell-language-server/issues/221
when (os == "linux") $ do
initObjLinker hscEnv'
res <- loadDLL hscEnv' "libm.so.6"
case res of
Nothing -> pure ()
Just err -> logWith recorder Error $ LogDLLLoadError err

forM (Map.elems cis) $ \ci -> do
let df = componentDynFlags ci
Expand All @@ -856,10 +852,26 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
-- which we need for any changes to the package flags in the dynflags
-- to be visible.
-- See #2693
evalGhcEnv hsc_env $ do
evalGhcEnv hscEnv' $ do
_ <- setSessionDynFlags df
getSession
#endif
-- Whenever we spin up a session on Linux, dynamically load libm.so.6
-- in. We need this in case the binary is statically linked, in which
-- case the interactive session will fail when trying to load
-- ghc-prim, which happens whenever Template Haskell is being
-- evaluated or haskell-language-server's eval plugin tries to run
-- some code. If the binary is dynamically linked, then this will have
-- no effect.
-- See https://github.com/haskell/haskell-language-server/issues/221
-- We need to do this after the call to setSessionDynFlags initialises
-- the loader
when (os == "linux") $ do
initObjLinker thisEnv
res <- loadDLL thisEnv "libm.so.6"
case res of
Nothing -> pure ()
Just err -> logWith recorder Error $ LogDLLLoadError err
henv <- createHscEnvEq thisEnv (zip uids dfs)
let targetEnv = ([], Just henv)
targetDepends = componentDependencyInfo ci
Expand Down

0 comments on commit 5d708f3

Please sign in to comment.