Skip to content

Commit 5a6cdfd

Browse files
committed
9.4 support + MHU
1 parent 291416b commit 5a6cdfd

File tree

36 files changed

+1159
-204
lines changed

36 files changed

+1159
-204
lines changed

cabal-941.project

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

ghcide/ghcide.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ test-suite ghcide-tests
350350
--------------------------------------------------------------
351351
ghcide,
352352
ghcide-test-utils-internal,
353-
ghc-typelits-knownnat,
354353
lsp,
355354
lsp-types,
356355
hls-plugin-api,
@@ -378,6 +377,8 @@ test-suite ghcide-tests
378377
build-depends:
379378
record-dot-preprocessor,
380379
record-hasfield
380+
if impl(ghc < 9.3)
381+
build-depends: ghc-typelits-knownnat
381382
hs-source-dirs: test/cabal test/exe bench/lib
382383
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
383384
main-is: Main.hs

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

Lines changed: 43 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,10 @@ import HieDb.Types
100101
import HieDb.Utils
101102
import qualified System.Random as Random
102103
import System.Random (RandomGen)
104+
import Control.Monad.IO.Unlift (MonadUnliftIO)
105+
import Debug.Trace
106+
import Control.Exception (evaluate)
107+
import Control.DeepSeq
103108

104109
data Log
105110
= LogSettingInitialDynFlags
@@ -208,11 +213,13 @@ data SessionLoadingOptions = SessionLoadingOptions
208213
, getCacheDirs :: String -> [String] -> IO CacheDirs
209214
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
210215
, getInitialGhcLibDir :: Recorder (WithPriority Log) -> FilePath -> IO (Maybe LibDir)
216+
#if !MIN_VERSION_ghc(9,3,0)
211217
, fakeUid :: UnitId
212218
-- ^ unit id used to tag the internal component built by ghcide
213219
-- To reuse external interface files the unit ids must match,
214220
-- thus make sure to build them with `--this-unit-id` set to the
215221
-- same value as the ghcide fake uid
222+
#endif
216223
}
217224

218225
instance Default SessionLoadingOptions where
@@ -221,7 +228,9 @@ instance Default SessionLoadingOptions where
221228
,loadCradle = loadWithImplicitCradle
222229
,getCacheDirs = getCacheDirsDefault
223230
,getInitialGhcLibDir = getInitialGhcLibDirDefault
231+
#if !MIN_VERSION_ghc(9,3,0)
224232
,fakeUid = Compat.toUnitId (Compat.stringToUnit "main")
233+
#endif
225234
}
226235

227236
-- | Find the cradle for a given 'hie.yaml' configuration.
@@ -494,7 +503,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
494503
new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do
495504
-- Remove all inplace dependencies from package flags for
496505
-- components in this HscEnv
506+
#if MIN_VERSION_ghc(9,3,0)
507+
let (df2, uids) = (rawComponentDynFlags, [])
508+
#else
497509
let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags
510+
#endif
498511
let prefix = show rawComponentUnitId
499512
-- See Note [Avoiding bad interface files]
500513
let hscComponents = sort $ map show uids
@@ -517,10 +530,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
517530
-- that I do not fully understand
518531
log Info $ LogMakingNewHscEnv inplace
519532
hscEnv <- emptyHscEnv ideNc libDir
520-
newHscEnv <-
533+
!newHscEnv <-
521534
-- Add the options for the current component to the HscEnv
522535
evalGhcEnv hscEnv $ do
523-
_ <- setSessionDynFlags $ setHomeUnitId_ fakeUid df
536+
_ <- setSessionDynFlags
537+
#if !MIN_VERSION_ghc(9,3,0)
538+
$ setHomeUnitId_ fakeUid
539+
#endif
540+
df
524541
getSession
525542

526543
-- Modify the map so the hieYaml now maps to the newly created
@@ -718,7 +735,11 @@ cradleToOptsAndLibDir recorder cradle file = do
718735
logWith recorder Info $ LogNoneCradleFound file
719736
return (Left [])
720737

738+
#if MIN_VERSION_ghc(9,3,0)
739+
emptyHscEnv :: NameCache -> FilePath -> IO HscEnv
740+
#else
721741
emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
742+
#endif
722743
emptyHscEnv nc libDir = do
723744
env <- runGhc (Just libDir) getSession
724745
initDynLinker env
@@ -757,7 +778,11 @@ toFlagsMap TargetDetails{..} =
757778
[ (l, (targetEnv, targetDepends)) | l <- targetLocations]
758779

759780

781+
#if MIN_VERSION_ghc(9,3,0)
782+
setNameCache :: NameCache -> HscEnv -> HscEnv
783+
#else
760784
setNameCache :: IORef NameCache -> HscEnv -> HscEnv
785+
#endif
761786
setNameCache nc hsc = hsc { hsc_NC = nc }
762787

763788
-- | Create a mapping from FilePaths to HscEnvEqs
@@ -773,6 +798,11 @@ newComponentCache
773798
newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
774799
let df = componentDynFlags ci
775800
hscEnv' <-
801+
#if MIN_VERSION_ghc(9,3,0)
802+
-- Set up a multi component session with the other units on GHC 9.4
803+
Compat.initUnits (map snd uids) (hscSetFlags df hsc_env)
804+
#elif MIN_VERSION_ghc(9,3,0)
805+
-- This initializes the units for GHC 9.2
776806
-- Add the options for the current component to the HscEnv
777807
-- We want to call `setSessionDynFlags` instead of `hscSetFlags`
778808
-- because `setSessionDynFlags` also initializes the package database,
@@ -782,14 +812,20 @@ newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
782812
evalGhcEnv hsc_env $ do
783813
_ <- setSessionDynFlags $ df
784814
getSession
815+
#else
816+
-- getOptions is enough to initialize units on GHC <9.2
817+
pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
818+
#endif
785819

820+
traceM "got new hsc env"
786821

787822
let newFunc = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
788823
henv <- newFunc hscEnv' uids
789824
let targetEnv = ([], Just henv)
790825
targetDepends = componentDependencyInfo ci
791826
res = (targetEnv, targetDepends)
792827
logWith recorder Debug $ LogNewComponentCache res
828+
evaluate $ liftRnf rwhnf $ componentTargets ci
793829

794830
let mk t = fromTargetId (importPaths df) exts (targetId t) targetEnv targetDepends
795831
ctargets <- concatMapM mk (componentTargets ci)
@@ -998,9 +1034,11 @@ setOptions (ComponentOptions theOpts compRoot _) dflags = do
9981034
-- initPackages parses the -package flags and
9991035
-- sets up the visibility for each component.
10001036
-- 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)
1037+
-- This only works for GHC <9.2
1038+
-- For GHC >= 9.2, we need to modify the unit env in the hsc_dflags, which
1039+
-- is done later in newComponentCache
1040+
final_flags <- liftIO $ wrapPackageSetupException $ Compat.oldInitUnits dflags''
1041+
return (final_flags, targets)
10041042

10051043
setIgnoreInterfacePragmas :: DynFlags -> DynFlags
10061044
setIgnoreInterfacePragmas df =

0 commit comments

Comments
 (0)