@@ -595,7 +595,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
595
595
-- For GHC's supporting multi component sessions, we create a shared
596
596
-- HscEnv but set the active component accordingly
597
597
hscEnv <- emptyHscEnv ideNc _libDir
598
- let new_cache = newComponentCache' recorder optExtensions cfps hscEnv
598
+ let new_cache = newComponentCache recorder optExtensions cfps hscEnv
599
599
all_target_details <- new_cache old_deps new_deps
600
600
let all_targets' = concat all_target_details
601
601
flags_map' = HM. fromList (concatMap toFlagsMap all_targets')
@@ -944,15 +944,15 @@ checkHomeUnitsClosed' ue home_id_set
944
944
-- This combines all the components we know about into
945
945
-- an appropriate session, which is a multi component
946
946
-- session on GHC 9.4+
947
- newComponentCache'
947
+ newComponentCache
948
948
:: Recorder (WithPriority Log )
949
949
-> [String ] -- ^ File extensions to consider
950
950
-> [NormalizedFilePath ] -- ^ Path to file that caused the creation of this component
951
951
-> HscEnv -- ^ An empty HscEnv
952
952
-> [ComponentInfo ] -- ^ New components to be loaded
953
953
-> [ComponentInfo ] -- ^ old, already existing components
954
954
-> IO [ [TargetDetails ] ]
955
- newComponentCache' recorder exts cfps hsc_env old_cis new_cis = do
955
+ newComponentCache recorder exts cfps hsc_env old_cis new_cis = do
956
956
let cis = Map. unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
957
957
-- When we have multiple components with the same uid,
958
958
-- prefer the new one over the old.
@@ -1008,74 +1008,6 @@ newComponentCache' recorder exts cfps hsc_env old_cis new_cis = do
1008
1008
1009
1009
return (L. nubOrdOn targetTarget ctargets)
1010
1010
1011
- -- | Create a mapping from FilePaths to HscEnvEqs
1012
- -- This combines all the components we know about into
1013
- -- an appropriate session, which is a multi component
1014
- -- session on GHC 9.4+
1015
- newComponentCache
1016
- :: Recorder (WithPriority Log )
1017
- -> [String ] -- ^ File extensions to consider
1018
- -> NormalizedFilePath -- ^ Path to file that caused the creation of this component
1019
- -> HscEnv -- ^ An empty HscEnv
1020
- -> [ComponentInfo ] -- ^ New components to be loaded
1021
- -> [ComponentInfo ] -- ^ old, already existing components
1022
- -> IO [ [TargetDetails ] ]
1023
- newComponentCache recorder exts _cfp hsc_env old_cis new_cis = do
1024
- let cis = Map. unionWith unionCIs (mkMap new_cis) (mkMap old_cis)
1025
- -- When we have multiple components with the same uid,
1026
- -- prefer the new one over the old.
1027
- -- However, we might have added some targets to the old unit
1028
- -- (see special target), so preserve those
1029
- unionCIs new_ci old_ci = new_ci { componentTargets = componentTargets new_ci ++ componentTargets old_ci }
1030
- mkMap = Map. fromListWith unionCIs . map (\ ci -> (componentUnitId ci, ci))
1031
- let dfs = map componentDynFlags $ Map. elems cis
1032
- uids = Map. keys cis
1033
- logWith recorder Info $ LogMakingNewHscEnv uids
1034
- hscEnv' <- -- Set up a multi component session with the other units on GHC 9.4
1035
- Compat. initUnits dfs hsc_env
1036
-
1037
- let closure_errs = checkHomeUnitsClosed' (hsc_unit_env hscEnv') (hsc_all_home_unit_ids hscEnv')
1038
- multi_errs = map (ideErrorWithSource (Just " cradle" ) (Just DiagnosticSeverity_Warning ) _cfp . T. pack . Compat. printWithoutUniques) closure_errs
1039
- bad_units = OS. fromList $ concat $ do
1040
- x <- bagToList $ mapBag errMsgDiagnostic $ unionManyBags $ map Compat. getMessages closure_errs
1041
- DriverHomePackagesNotClosed us <- pure x
1042
- pure us
1043
- isBad ci = (homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units
1044
- -- Whenever we spin up a session on Linux, dynamically load libm.so.6
1045
- -- in. We need this in case the binary is statically linked, in which
1046
- -- case the interactive session will fail when trying to load
1047
- -- ghc-prim, which happens whenever Template Haskell is being
1048
- -- evaluated or haskell-language-server's eval plugin tries to run
1049
- -- some code. If the binary is dynamically linked, then this will have
1050
- -- no effect.
1051
- -- See https://github.com/haskell/haskell-language-server/issues/221
1052
- -- We need to do this after the call to setSessionDynFlags initialises
1053
- -- the loader
1054
- when (os == " linux" ) $ do
1055
- initObjLinker hscEnv'
1056
- res <- loadDLL hscEnv' " libm.so.6"
1057
- case res of
1058
- Nothing -> pure ()
1059
- Just err -> logWith recorder Error $ LogDLLLoadError err
1060
-
1061
- forM (Map. elems cis) $ \ ci -> do
1062
- let df = componentDynFlags ci
1063
- thisEnv <- do
1064
- -- In GHC 9.4 we have multi component support, and we have initialised all the units
1065
- -- above.
1066
- -- We just need to set the current unit here
1067
- pure $ hscSetActiveUnitId (homeUnitId_ df) hscEnv'
1068
- henv <- newHscEnvEq thisEnv
1069
- let targetEnv = (if isBad ci then multi_errs else [] , Just henv)
1070
- targetDepends = componentDependencyInfo ci
1071
- logWith recorder Debug $ LogNewComponentCache (targetEnv, targetDepends)
1072
- evaluate $ liftRnf rwhnf $ componentTargets ci
1073
-
1074
- let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
1075
- ctargets <- concatMapM mk (componentTargets ci)
1076
-
1077
- return (L. nubOrdOn targetTarget ctargets)
1078
-
1079
1011
{- Note [Avoiding bad interface files]
1080
1012
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1081
1013
Originally, we set the cache directory for the various components once
0 commit comments