Skip to content

Commit

Permalink
9.4 support + MHU
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Aug 31, 2022
1 parent fdbc555 commit 111901f
Show file tree
Hide file tree
Showing 70 changed files with 1,362 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
cabal:
description: "Cabal version"
required: false
default: "3.6"
default: "3.8.1.0"
os:
description: "Operating system: Linux, Windows or macOS"
required: true
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ jobs:
strategy:
fail-fast: true
matrix:
ghc: [ "9.2.4"
ghc: [ "9.4.2"
, "9.4.1"
, "9.2.4"
, "9.2.3"
, "9.0.2"
, "8.10.7"
Expand All @@ -69,6 +71,9 @@ jobs:
]
include:
# only test supported ghc major versions
- os: ubuntu-latest
ghc: '9.4.2'
test: true
- os: ubuntu-latest
ghc: '9.2.4'
test: true
Expand All @@ -84,6 +89,9 @@ jobs:
- os: ubuntu-latest
ghc: '8.6.5'
test: true
- os: windows-latest
ghc: '9.4.2'
test: true
- os: windows-latest
ghc: '9.2.4'
test: true
Expand Down
6 changes: 5 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variables:
# Commit of ghc/ci-images repository from which to pull Docker images
DOCKER_REV: "4ed1a4f27828ba96a34662dc954335e29b470cd2"

CABAL_INSTALL_VERSION: 3.6.2.0
CABAL_INSTALL_VERSION: 3.8.1.0

.windows_matrix: &windows_matrix
matrix:
Expand All @@ -21,6 +21,10 @@ variables:
CABAL_PROJECT: cabal.project
- GHC_VERSION: 9.2.4
CABAL_PROJECT: cabal.project
- GHC_VERSION: 9.4.1
CABAL_PROJECT: cabal.project
- GHC_VERSION: 9.4.2
CABAL_PROJECT: cabal.project

workflow:
rules:
Expand Down
2 changes: 2 additions & 0 deletions bindist/ghcs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
9.0.2,cabal.project
9.2.3,cabal.project
9.2.4,cabal.project
9.4.1,cabal.project
9.4.2,cabal.project
2 changes: 2 additions & 0 deletions bindist/ghcs-Msys
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
9.0.2,cabal.project
9.2.3,cabal.project
9.2.4,cabal.project
9.4.1,cabal.project
9.4.2,cabal.project
13 changes: 13 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ source-repository-package
tag: 7a0af7a8fd38045fd15fb13445bdcc7085325460
-- https://github.com/tibbe/ekg-json/pull/12

source-repository-package
type:git
location: https://github.com/wz1000/hiedb
tag: 67b92df2359558091df9102db5b701327308b930

source-repository-package
type:git
location: https://github.com/wz1000/hie-bios
tag: aa73d3d2eb89df0003d2468a105e326d71b62cc7

-- Needed for ghcide-bench until a new release of lsp-test is out
source-repository-package
type:git
Expand All @@ -76,6 +86,9 @@ source-repository-package
-- https://github.com/haskell/lsp/pull/450

allow-newer:
base, ghc-prim, ghc-bignum, ghc, Cabal, binary, bytestring, unix, time, template-haskell,
ghc-paths:Cabal,

-- ghc-9.2
----------
hiedb:base,
Expand Down
3 changes: 2 additions & 1 deletion ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ test-suite ghcide-tests
--------------------------------------------------------------
ghcide,
ghcide-test-utils-internal,
ghc-typelits-knownnat,
lsp,
lsp-types,
hls-plugin-api,
Expand Down Expand Up @@ -378,6 +377,8 @@ test-suite ghcide-tests
build-depends:
record-dot-preprocessor,
record-hasfield
if impl(ghc < 9.3)
build-depends: ghc-typelits-knownnat
hs-source-dirs: test/cabal test/exe bench/lib
ghc-options: -threaded -Wall -Wno-name-shadowing -O0 -Wno-unticked-promoted-constructors
main-is: Main.hs
Expand Down
47 changes: 41 additions & 6 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}

{-|
The logic for setting up a ghcide session by tapping into hie-bios.
Expand Down Expand Up @@ -100,6 +101,9 @@ import HieDb.Types
import HieDb.Utils
import qualified System.Random as Random
import System.Random (RandomGen)
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Exception (evaluate)
import Control.DeepSeq

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

instance Default SessionLoadingOptions where
Expand All @@ -221,7 +227,9 @@ instance Default SessionLoadingOptions where
,loadCradle = loadWithImplicitCradle
,getCacheDirs = getCacheDirsDefault
,getInitialGhcLibDir = getInitialGhcLibDirDefault
#if !MIN_VERSION_ghc(9,3,0)
,fakeUid = Compat.toUnitId (Compat.stringToUnit "main")
#endif
}

-- | Find the cradle for a given 'hie.yaml' configuration.
Expand Down Expand Up @@ -494,7 +502,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do
-- Remove all inplace dependencies from package flags for
-- components in this HscEnv
#if MIN_VERSION_ghc(9,3,0)
let (df2, uids) = (rawComponentDynFlags, [])
#else
let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags
#endif
let prefix = show rawComponentUnitId
-- See Note [Avoiding bad interface files]
let hscComponents = sort $ map show uids
Expand All @@ -517,10 +529,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
-- that I do not fully understand
log Info $ LogMakingNewHscEnv inplace
hscEnv <- emptyHscEnv ideNc libDir
newHscEnv <-
!newHscEnv <-
-- Add the options for the current component to the HscEnv
evalGhcEnv hscEnv $ do
_ <- setSessionDynFlags $ setHomeUnitId_ fakeUid df
_ <- setSessionDynFlags
#if !MIN_VERSION_ghc(9,3,0)
$ setHomeUnitId_ fakeUid
#endif
df
getSession

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

#if MIN_VERSION_ghc(9,3,0)
emptyHscEnv :: NameCache -> FilePath -> IO HscEnv
#else
emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
#endif
emptyHscEnv nc libDir = do
env <- runGhc (Just libDir) getSession
initDynLinker env
Expand Down Expand Up @@ -757,7 +777,11 @@ toFlagsMap TargetDetails{..} =
[ (l, (targetEnv, targetDepends)) | l <- targetLocations]


#if MIN_VERSION_ghc(9,3,0)
setNameCache :: NameCache -> HscEnv -> HscEnv
#else
setNameCache :: IORef NameCache -> HscEnv -> HscEnv
#endif
setNameCache nc hsc = hsc { hsc_NC = nc }

-- | Create a mapping from FilePaths to HscEnvEqs
Expand All @@ -773,6 +797,11 @@ newComponentCache
newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
let df = componentDynFlags ci
hscEnv' <-
#if MIN_VERSION_ghc(9,3,0)
-- Set up a multi component session with the other units on GHC 9.4
Compat.initUnits (map snd uids) (hscSetFlags df hsc_env)
#elif MIN_VERSION_ghc(9,2,0)
-- This initializes the units for GHC 9.2
-- Add the options for the current component to the HscEnv
-- We want to call `setSessionDynFlags` instead of `hscSetFlags`
-- because `setSessionDynFlags` also initializes the package database,
Expand All @@ -782,14 +811,18 @@ newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
evalGhcEnv hsc_env $ do
_ <- setSessionDynFlags $ df
getSession

#else
-- getOptions is enough to initialize units on GHC <9.2
pure $ hscSetFlags df hsc_env { hsc_IC = (hsc_IC hsc_env) { ic_dflags = df } }
#endif

let newFunc = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
henv <- newFunc hscEnv' uids
let targetEnv = ([], Just henv)
targetDepends = componentDependencyInfo ci
res = (targetEnv, targetDepends)
logWith recorder Debug $ LogNewComponentCache res
evaluate $ liftRnf rwhnf $ componentTargets ci

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

setIgnoreInterfacePragmas :: DynFlags -> DynFlags
setIgnoreInterfacePragmas df =
Expand Down
Loading

0 comments on commit 111901f

Please sign in to comment.