@@ -729,7 +729,17 @@ emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
729
729
#endif
730
730
emptyHscEnv nc libDir = do
731
731
-- 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
733
743
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)
734
744
735
745
data TargetDetails = TargetDetails
@@ -824,20 +834,6 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
824
834
#else
825
835
do
826
836
#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
841
837
842
838
forM (Map. elems cis) $ \ ci -> do
843
839
let df = componentDynFlags ci
@@ -856,10 +852,26 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
856
852
-- which we need for any changes to the package flags in the dynflags
857
853
-- to be visible.
858
854
-- See #2693
859
- evalGhcEnv hsc_env $ do
855
+ evalGhcEnv hscEnv' $ do
860
856
_ <- setSessionDynFlags df
861
857
getSession
862
858
#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
863
875
henv <- createHscEnvEq thisEnv (zip uids dfs)
864
876
let targetEnv = ([] , Just henv)
865
877
targetDepends = componentDependencyInfo ci
0 commit comments