@@ -729,8 +729,17 @@ emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
729729#endif
730730emptyHscEnv 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+ env <- runGhc (Just libDir) $
734+ getSessionDynFlags >>= setSessionDynFlags >> getSession
735+ -- On GHC 9.2 calling setSessionDynFlags caches the unit databases
736+ -- for an empty environment. This prevents us from reading the
737+ -- package database subsequently. So clear the unit db cache in
738+ -- hsc_unit_dbs
733739 pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)
740+ #if !MIN_VERSION_ghc(9,3,0)
741+ {hsc_unit_dbs = Nothing }
742+ #endif
734743
735744data TargetDetails = TargetDetails
736745 {
@@ -832,6 +841,8 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
832841 -- some code. If the binary is dynamically linked, then this will have
833842 -- no effect.
834843 -- See https://github.com/haskell/haskell-language-server/issues/221
844+ -- We need to do this after the call to setSessionDynFlags initialises
845+ -- the loader
835846 when (os == " linux" ) $ do
836847 initObjLinker hscEnv'
837848 res <- loadDLL hscEnv' " libm.so.6"
@@ -856,7 +867,7 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
856867 -- which we need for any changes to the package flags in the dynflags
857868 -- to be visible.
858869 -- See #2693
859- evalGhcEnv hsc_env $ do
870+ evalGhcEnv hscEnv' $ do
860871 _ <- setSessionDynFlags df
861872 getSession
862873#endif
0 commit comments