Skip to content

Commit a478a75

Browse files
committed
WIP evaluate CPP
1 parent 287ee42 commit a478a75

File tree

33 files changed

+15
-836
lines changed

33 files changed

+15
-836
lines changed

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

-51
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ import Text.ParserCombinators.ReadP (readP_to_S)
120120

121121
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
122122

123-
#if MIN_VERSION_ghc(9,3,0)
124123
import qualified Data.Set as OS
125124
import qualified Development.IDE.GHC.Compat.Util as Compat
126125
import GHC.Data.Graph.Directed
@@ -131,7 +130,6 @@ import GHC.Driver.Errors.Types
131130
import GHC.Types.Error (errMsgDiagnostic,
132131
singleMessage)
133132
import GHC.Unit.State
134-
#endif
135133

136134
data Log
137135
= LogSettingInitialDynFlags
@@ -245,13 +243,6 @@ data SessionLoadingOptions = SessionLoadingOptions
245243
, getCacheDirs :: String -> [String] -> IO CacheDirs
246244
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
247245
, getInitialGhcLibDir :: Recorder (WithPriority Log) -> FilePath -> IO (Maybe LibDir)
248-
#if !MIN_VERSION_ghc(9,3,0)
249-
, fakeUid :: UnitId
250-
-- ^ unit id used to tag the internal component built by ghcide
251-
-- To reuse external interface files the unit ids must match,
252-
-- thus make sure to build them with `--this-unit-id` set to the
253-
-- same value as the ghcide fake uid
254-
#endif
255246
}
256247

257248
instance Default SessionLoadingOptions where
@@ -260,9 +251,6 @@ instance Default SessionLoadingOptions where
260251
,loadCradle = loadWithImplicitCradle
261252
,getCacheDirs = getCacheDirsDefault
262253
,getInitialGhcLibDir = getInitialGhcLibDirDefault
263-
#if !MIN_VERSION_ghc(9,3,0)
264-
,fakeUid = Compat.toUnitId (Compat.stringToUnit "main")
265-
#endif
266254
}
267255

268256
-- | Find the cradle for a given 'hie.yaml' configuration.
@@ -542,11 +530,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
542530
all_deps' <- forM all_deps $ \RawComponentInfo{..} -> do
543531
-- Remove all inplace dependencies from package flags for
544532
-- components in this HscEnv
545-
#if MIN_VERSION_ghc(9,3,0)
546533
let (df2, uids) = (rawComponentDynFlags, [])
547-
#else
548-
let (df2, uids) = _removeInplacePackages fakeUid _inplace rawComponentDynFlags
549-
#endif
550534
let prefix = show rawComponentUnitId
551535
-- See Note [Avoiding bad interface files]
552536
let hscComponents = sort $ map show uids
@@ -771,11 +755,7 @@ cradleToOptsAndLibDir recorder loadConfig cradle file old_fps = do
771755
PreferSingleComponentLoading -> LoadFile
772756
PreferMultiComponentLoading -> LoadWithContext old_fps
773757

774-
#if MIN_VERSION_ghc(9,3,0)
775758
emptyHscEnv :: NameCache -> FilePath -> IO HscEnv
776-
#else
777-
emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
778-
#endif
779759
emptyHscEnv nc libDir = do
780760
-- We call setSessionDynFlags so that the loader is initialised
781761
-- We need to do this before we call initUnits.
@@ -786,9 +766,6 @@ emptyHscEnv nc libDir = do
786766
-- package database subsequently. So clear the unit db cache in
787767
-- hsc_unit_dbs
788768
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)
789-
#if !MIN_VERSION_ghc(9,3,0)
790-
{hsc_unit_dbs = Nothing}
791-
#endif
792769

793770
data TargetDetails = TargetDetails
794771
{
@@ -826,14 +803,9 @@ toFlagsMap TargetDetails{..} =
826803
[ (l, (targetEnv, targetDepends)) | l <- targetLocations]
827804

828805

829-
#if MIN_VERSION_ghc(9,3,0)
830806
setNameCache :: NameCache -> HscEnv -> HscEnv
831-
#else
832-
setNameCache :: IORef NameCache -> HscEnv -> HscEnv
833-
#endif
834807
setNameCache nc hsc = hsc { hsc_NC = nc }
835808

836-
#if MIN_VERSION_ghc(9,3,0)
837809
-- This function checks the important property that if both p and q are home units
838810
-- then any dependency of p, which transitively depends on q is also a home unit.
839811
-- GHC had an implementation of this function, but it was horribly inefficient
@@ -890,7 +862,6 @@ checkHomeUnitsClosed' ue home_id_set
890862
Just depends ->
891863
let todo'' = (depends OS.\\ done) `OS.union` todo'
892864
in DigraphNode uid uid (OS.toList depends) : go (OS.insert uid done) todo''
893-
#endif
894865

895866
-- | Create a mapping from FilePaths to HscEnvEqs
896867
-- This combines all the components we know about into
@@ -920,18 +891,13 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis dir = do
920891
hscEnv' <- -- Set up a multi component session with the other units on GHC 9.4
921892
Compat.initUnits dfs hsc_env
922893

923-
#if MIN_VERSION_ghc(9,3,0)
924894
let closure_errs = checkHomeUnitsClosed' (hsc_unit_env hscEnv') (hsc_all_home_unit_ids hscEnv')
925895
multi_errs = map (ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Warning) _cfp . T.pack . Compat.printWithoutUniques) closure_errs
926896
bad_units = OS.fromList $ concat $ do
927897
x <- bagToList $ mapBag errMsgDiagnostic $ unionManyBags $ map Compat.getMessages closure_errs
928898
DriverHomePackagesNotClosed us <- pure x
929899
pure us
930900
isBad ci = (homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units
931-
#else
932-
let isBad = const False
933-
multi_errs = []
934-
#endif
935901
-- Whenever we spin up a session on Linux, dynamically load libm.so.6
936902
-- in. We need this in case the binary is statically linked, in which
937903
-- case the interactive session will fail when trying to load
@@ -953,23 +919,10 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis dir = do
953919
let df = componentDynFlags ci
954920
let createHscEnvEq = maybe newHscEnvEqPreserveImportPaths (newHscEnvEq dir) cradlePath
955921
thisEnv <- do
956-
#if MIN_VERSION_ghc(9,3,0)
957922
-- In GHC 9.4 we have multi component support, and we have initialised all the units
958923
-- above.
959924
-- We just need to set the current unit here
960925
pure $ hscSetActiveUnitId (homeUnitId_ df) hscEnv'
961-
#else
962-
-- This initializes the units for GHC 9.2
963-
-- Add the options for the current component to the HscEnv
964-
-- We want to call `setSessionDynFlags` instead of `hscSetFlags`
965-
-- because `setSessionDynFlags` also initializes the package database,
966-
-- which we need for any changes to the package flags in the dynflags
967-
-- to be visible.
968-
-- See #2693
969-
evalGhcEnv hscEnv' $ do
970-
_ <- setSessionDynFlags df
971-
getSession
972-
#endif
973926
henv <- createHscEnvEq thisEnv (zip uids dfs)
974927
let targetEnv = (if isBad ci then multi_errs else [], Just henv)
975928
targetDepends = componentDependencyInfo ci
@@ -1201,7 +1154,6 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
12011154
initOne this_opts = do
12021155
(dflags', targets') <- addCmdOpts this_opts dflags
12031156
let dflags'' =
1204-
#if MIN_VERSION_ghc(9,3,0)
12051157
case unitIdString (homeUnitId_ dflags') of
12061158
-- cabal uses main for the unit id of all executable packages
12071159
-- This makes multi-component sessions confused about what
@@ -1214,9 +1166,6 @@ setOptions cfp (ComponentOptions theOpts compRoot _) dflags rootDir = do
12141166
hashed_uid = Compat.toUnitId (Compat.stringToUnit ("main-"++hash))
12151167
in setHomeUnitId_ hashed_uid dflags'
12161168
_ -> dflags'
1217-
#else
1218-
dflags'
1219-
#endif
12201169

12211170
let targets = makeTargetsAbsolute root targets'
12221171
root = case workingDirectory dflags'' of

0 commit comments

Comments
 (0)