Skip to content

Commit 7f5bd1d

Browse files
committed
9.4 support + MHU
1 parent 44be741 commit 7f5bd1d

36 files changed

+1048
-145
lines changed

cabal-941.project

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
packages:
2+
./hie-compat
3+
./shake-bench
4+
./hls-graph
5+
./ghcide
6+
./hls-plugin-api
7+
8+
tests: false
9+
10+
-- Standard location for temporary packages needed for particular environments
11+
-- For example it is used in the project gitlab mirror to help in the MAcOS M1 build script
12+
-- See https://github.com/haskell/haskell-language-server/blob/master/.gitlab-ci.yml
13+
optional-packages: vendored/*/*.cabal
14+
15+
16+
tests: false
17+
18+
package *
19+
-- ghc 8.10 cannot build ghc-lib 9.2 with --haddock
20+
-- ghc-options: -haddock
21+
test-show-details: direct
22+
23+
write-ghc-environment-files: never
24+
25+
index-state: 2022-06-12T00:00:00Z
26+
allow-newer:
27+
base, ghc-prim, ghc-bignum, ghc, Cabal, binary, bytestring, unix, time, template-haskell,
28+
ghc-paths:Cabal,
29+
-- for shake-bench
30+
Chart:lens,
31+
Chart-diagrams:lens,
32+
33+
constraints:
34+
hyphenation +embed,
35+
-- remove this when hlint sets ghc-lib to true by default
36+
-- https://github.com/ndmitchell/hlint/issues/1376
37+
hlint +ghc-lib,
38+
ghc-lib-parser-ex -auto,
39+
stylish-haskell +ghc-lib
40+
41+
source-repository-package
42+
type:git
43+
location: https://github.com/wz1000/hiedb
44+
tag: 217dd47246ce0708b0152c78b3c6268373824a22
45+
46+
source-repository-package
47+
type:git
48+
location: https://github.com/wz1000/hie-bios
49+
tag: 0e1b0f8e0a77ef6d203d725dd2bae364dc3466f2
50+
51+
-- This is benign and won't affect our ability to release to Hackage,
52+
-- because we only depend on `ekg-json` when a non-default flag
53+
-- is turned on.
54+
source-repository-package
55+
type:git
56+
location: https://github.com/pepeiborra/ekg-json
57+
tag: 7a0af7a8fd38045fd15fb13445bdcc7085325460
58+
59+
allow-newer:
60+
-- ghc-9.2
61+
----------
62+
hiedb:base,
63+
64+
ekg-wai:time,
65+
-- for shake-bench
66+
Chart-diagrams:diagrams-core,
67+
SVGFonts:diagrams-core,
68+
69+
-- https://github.com/lspitzner/multistate/pull/8
70+
multistate:base,
71+
-- https://github.com/lspitzner/data-tree-print/pull/3
72+
data-tree-print:base,
73+
-- https://github.com/lspitzner/butcher/pull/8
74+
butcher:base,
75+
76+
implicit-hie-cradle:bytestring,
77+
implicit-hie-cradle:time
78+
79+
allow-older:
80+
primitive-extras:primitive-unlifted
81+
82+
repository head.hackage.ghc.haskell.org
83+
url: https://ghc.gitlab.haskell.org/head.hackage/
84+
secure: True
85+
key-threshold: 3
86+
root-keys:
87+
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
88+
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
89+
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
90+
91+
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override

ghcide/ghcide.cabal

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ library
5959
filepath,
6060
fingertree,
6161
focus,
62-
ghc-exactprint,
62+
-- ghc-exactprint,
6363
ghc-trace-events,
6464
Glob,
6565
haddock-library >= 1.8 && < 1.11,
@@ -80,7 +80,6 @@ library
8080
prettyprinter >= 1.6,
8181
random,
8282
regex-tdfa >= 1.3.1.0,
83-
retrie,
8483
rope-utf16-splay,
8584
safe,
8685
safe-exceptions,
@@ -113,7 +112,11 @@ library
113112
hie-bios ^>= 0.9.1,
114113
implicit-hie-cradle ^>= 0.3.0.5 || ^>= 0.5,
115114
base16-bytestring >=0.1.1 && <1.1
116-
if impl(ghc >= 9.2)
115+
if impl(ghc < 9.3)
116+
build-depends:
117+
retrie,
118+
ghc-exactprint
119+
if impl(ghc >= 9.2 && < 9.3)
117120
build-depends:
118121
ghc-exactprint >= 1.4
119122
if os(windows)

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE ExistentialQuantification #-}
22
{-# LANGUAGE RankNTypes #-}
33
{-# LANGUAGE TypeFamilies #-}
4+
{-# LANGUAGE CPP #-}
45

56
{-|
67
The logic for setting up a ghcide session by tapping into hie-bios.
@@ -100,6 +101,9 @@ import HieDb.Utils
100101
import System.Random (RandomGen)
101102
import qualified System.Random as Random
102103
import Control.Monad.IO.Unlift (MonadUnliftIO)
104+
import Debug.Trace
105+
import Control.Exception (evaluate)
106+
import Control.DeepSeq
103107

104108
data Log
105109
= LogSettingInitialDynFlags
@@ -208,11 +212,13 @@ data SessionLoadingOptions = SessionLoadingOptions
208212
, getCacheDirs :: String -> [String] -> IO CacheDirs
209213
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
210214
, getInitialGhcLibDir :: Recorder (WithPriority Log) -> FilePath -> IO (Maybe LibDir)
215+
#if !MIN_VERSION_ghc(9,3,0)
211216
, fakeUid :: UnitId
212217
-- ^ unit id used to tag the internal component built by ghcide
213218
-- To reuse external interface files the unit ids must match,
214219
-- thus make sure to build them with `--this-unit-id` set to the
215220
-- same value as the ghcide fake uid
221+
#endif
216222
}
217223

218224
instance Default SessionLoadingOptions where
@@ -221,7 +227,9 @@ instance Default SessionLoadingOptions where
221227
,loadCradle = loadWithImplicitCradle
222228
,getCacheDirs = getCacheDirsDefault
223229
,getInitialGhcLibDir = getInitialGhcLibDirDefault
230+
#if !MIN_VERSION_ghc(9,3,0)
224231
,fakeUid = Compat.toUnitId (Compat.stringToUnit "main")
232+
#endif
225233
}
226234

227235
-- | Find the cradle for a given 'hie.yaml' configuration.
@@ -494,7 +502,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
494502
new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do
495503
-- Remove all inplace dependencies from package flags for
496504
-- components in this HscEnv
505+
#if MIN_VERSION_ghc(9,3,0)
506+
let (df2, uids) = (rawComponentDynFlags, [])
507+
#else
497508
let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags
509+
#endif
498510
let prefix = show rawComponentUnitId
499511
-- See Note [Avoiding bad interface files]
500512
let hscComponents = sort $ map show uids
@@ -517,10 +529,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
517529
-- that I do not fully understand
518530
log Info $ LogMakingNewHscEnv inplace
519531
hscEnv <- emptyHscEnv ideNc libDir
520-
newHscEnv <-
532+
!newHscEnv <-
521533
-- Add the options for the current component to the HscEnv
522534
evalGhcEnv hscEnv $ do
523-
_ <- setSessionDynFlags $ setHomeUnitId_ fakeUid df
535+
_ <- setSessionDynFlags
536+
#if !MIN_VERSION_ghc(9,3,0)
537+
$ setHomeUnitId_ fakeUid
538+
#endif
539+
df
524540
getSession
525541

526542
-- Modify the map so the hieYaml now maps to the newly created
@@ -718,7 +734,11 @@ cradleToOptsAndLibDir recorder cradle file = do
718734
logWith recorder Info $ LogNoneCradleFound file
719735
return (Left [])
720736

737+
#if MIN_VERSION_ghc(9,3,0)
738+
emptyHscEnv :: NameCache -> FilePath -> IO HscEnv
739+
#else
721740
emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
741+
#endif
722742
emptyHscEnv nc libDir = do
723743
env <- runGhc (Just libDir) getSession
724744
initDynLinker env
@@ -757,7 +777,11 @@ toFlagsMap TargetDetails{..} =
757777
[ (l, (targetEnv, targetDepends)) | l <- targetLocations]
758778

759779

780+
#if MIN_VERSION_ghc(9,3,0)
781+
setNameCache :: NameCache -> HscEnv -> HscEnv
782+
#else
760783
setNameCache :: IORef NameCache -> HscEnv -> HscEnv
784+
#endif
761785
setNameCache nc hsc = hsc { hsc_NC = nc }
762786

763787
-- | Create a mapping from FilePaths to HscEnvEqs
@@ -773,6 +797,11 @@ newComponentCache
773797
newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
774798
let df = componentDynFlags ci
775799
hscEnv' <-
800+
#if MIN_VERSION_ghc(9,3,0)
801+
-- Set up a multi component session with the other units on GHC 9.4
802+
Compat.initUnits (map snd uids) (hscSetFlags df hsc_env)
803+
#elif MIN_VERSION_ghc(9,3,0)
804+
-- This initializes the units for GHC 9.2
776805
-- Add the options for the current component to the HscEnv
777806
-- We want to call `setSessionDynFlags` instead of `hscSetFlags`
778807
-- because `setSessionDynFlags` also initializes the package database,
@@ -782,14 +811,20 @@ newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
782811
evalGhcEnv hsc_env $ do
783812
_ <- setSessionDynFlags $ df
784813
getSession
814+
#else
815+
-- getOptions is enough to initialize units on GHC <9.2
816+
pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
817+
#endif
785818

819+
traceM "got new hsc env"
786820

787821
let newFunc = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
788822
henv <- newFunc hscEnv' uids
789823
let targetEnv = ([], Just henv)
790824
targetDepends = componentDependencyInfo ci
791825
res = (targetEnv, targetDepends)
792826
logWith recorder Debug $ LogNewComponentCache res
827+
evaluate $ liftRnf rwhnf $ componentTargets ci
793828

794829
let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
795830
ctargets <- concatMapM mk (componentTargets ci)
@@ -998,9 +1033,11 @@ setOptions (ComponentOptions theOpts compRoot _) dflags = do
9981033
-- initPackages parses the -package flags and
9991034
-- sets up the visibility for each component.
10001035
-- Throws if a -package flag cannot be satisfied.
1001-
env <- hscSetFlags dflags'' <$> getSession
1002-
final_env' <- liftIO $ wrapPackageSetupException $ Compat.initUnits env
1003-
return (hsc_dflags final_env', targets)
1036+
-- This only works for GHC <9.2
1037+
-- For GHC >= 9.2, we need to modify the unit env in the hsc_dflags, which
1038+
-- is done later in newComponentCache
1039+
final_flags <- liftIO $ wrapPackageSetupException $ Compat.oldInitUnits dflags''
1040+
return (final_flags, targets)
10041041

10051042
setIgnoreInterfacePragmas :: DynFlags -> DynFlags
10061043
setIgnoreInterfacePragmas df =

0 commit comments

Comments
 (0)