Skip to content

Commit 5d708f3

Browse files
committed
Some fixes for 9.2
1 parent fb934ab commit 5d708f3

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

ghcide/session-loader/Development/IDE/Session.hs

+28-16
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,17 @@ emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
729729
#endif
730730
emptyHscEnv nc libDir = do
731731
-- We call setSessionDynFlags so that the loader is initialised
732-
env <- runGhc (Just libDir) $ getSessionDynFlags >>= setSessionDynFlags >> getSession
732+
-- We need to do this before we call initUnits.
733+
-- However, on GHC 9.2 calling setSessionDynFlags too early
734+
-- can mess up the package db cache for some reason.
735+
-- So on 9.2 the loader is initialised by the call to setSessionDynFlags
736+
-- only after we actually have a proper set of DynFlags
737+
env <- runGhc (Just libDir) $
738+
#if MIN_VERSION_ghc(9,3,0)
739+
getSessionDynFlags >>= setSessionDynFlags >> getSession
740+
#else
741+
getSession
742+
#endif
733743
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)
734744

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

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

0 commit comments

Comments
 (0)