Skip to content

Commit a538f06

Browse files
authored
ghc initialization error handling (#609)
There are a couple of cases to handle as seen below. Thanks @jneira for help discovering them all. There used to be linking errors but I no longer see those after the multi-cradle patch Non Nix ========= The table below shows a couple of combinations of cradles and ghcide versions in a non-Nix environment. All the version mismatches are now handled as follows: - "Cannot satisfy package" - `-package-id` flags referencing package versions not available (generally base) - "bad interface" - tried to load an interface file created by a different version of ghc cradle/ghcide | 8.6 | 8.8 | 8.10 --------------|-----|----|--- Cabal 8.6 | success | cannot satisfy package | cannot satisfy package Cabal 8.8 | cannot satisfy package | success | cannot satisfy package Cabal 8.10 | cannot satisfy package | cannot satisfy package | success Stack 8.6 | success | bad-interface | bad-interfac- Stack 8.8 | bad-interface | success | bad-interface Stack 8.10 | bad-interface | bad-interface | success Nix ========= Because Nix redefines the libdir to point at the run-time ghc installation, it's actually much easier to detect a version mismatch: just compare the compile-time and run-time libdirs
1 parent e380aad commit a538f06

File tree

8 files changed

+252
-208
lines changed

8 files changed

+252
-208
lines changed

exe/Main.hs

Lines changed: 242 additions & 182 deletions
Large diffs are not rendered by default.

ghcide.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ executable ghcide
205205
directory,
206206
extra,
207207
filepath,
208-
ghc-check >= 0.3.0.1 && < 0.4,
208+
ghc-check >= 0.5.0.1 && < 0.6,
209209
ghc-paths,
210210
ghc,
211211
gitrev,
@@ -215,6 +215,7 @@ executable ghcide
215215
hie-bios >= 0.5.0 && < 0.6,
216216
ghcide,
217217
optparse-applicative,
218+
safe-exceptions,
218219
shake,
219220
text,
220221
unordered-containers

src/Development/IDE/GHC/Util.hs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
-- | General utility functions, mostly focused around GHC operations.
55
module Development.IDE.GHC.Util(
66
-- * HcsEnv and environment
7-
HscEnvEq(GhcVersionMismatch, compileTime, runTime), hscEnv, newHscEnvEq,
7+
HscEnvEq,
8+
hscEnv, newHscEnvEq,
89
modifyDynFlags,
910
evalGhcEnv,
1011
runGhcEnv,
@@ -38,7 +39,6 @@ import Fingerprint
3839
import GhcMonad
3940
import Control.Exception
4041
import Data.IORef
41-
import Data.Version (showVersion, Version)
4242
import FileCleanup
4343
import Foreign.Ptr
4444
import Foreign.ForeignPtr
@@ -170,49 +170,31 @@ data HscEnvEq
170170
[(InstalledUnitId, DynFlags)] -- In memory components for this HscEnv
171171
-- This is only used at the moment for the import dirs in
172172
-- the DynFlags
173-
| GhcVersionMismatch { compileTime :: !Version
174-
, runTime :: !Version
175-
}
176173

177174
-- | Unwrap an 'HsEnvEq'.
178175
hscEnv :: HscEnvEq -> HscEnv
179176
hscEnv = either error id . hscEnv'
180177

181178
hscEnv' :: HscEnvEq -> Either String HscEnv
182179
hscEnv' (HscEnvEq _ x _) = Right x
183-
hscEnv' GhcVersionMismatch{..} = Left $
184-
unwords
185-
["ghcide compiled against GHC"
186-
,showVersion compileTime
187-
,"but currently using"
188-
,showVersion runTime
189-
,". This is unsupported, ghcide must be compiled with the same GHC version as the project."
190-
]
191-
192180
deps :: HscEnvEq -> [(InstalledUnitId, DynFlags)]
193181
deps (HscEnvEq _ _ u) = u
194-
deps GhcVersionMismatch{} = []
195182

196183
-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
197184
newHscEnvEq :: HscEnv -> [(InstalledUnitId, DynFlags)] -> IO HscEnvEq
198185
newHscEnvEq e uids = do u <- newUnique; return $ HscEnvEq u e uids
199186

200187
instance Show HscEnvEq where
201188
show (HscEnvEq a _ _) = "HscEnvEq " ++ show (hashUnique a)
202-
show GhcVersionMismatch{..} = "GhcVersionMismatch " <> show (compileTime, runTime)
203189

204190
instance Eq HscEnvEq where
205191
HscEnvEq a _ _ == HscEnvEq b _ _ = a == b
206-
GhcVersionMismatch a b == GhcVersionMismatch c d = a == c && b == d
207-
_ == _ = False
208192

209193
instance NFData HscEnvEq where
210194
rnf (HscEnvEq a b c) = rnf (hashUnique a) `seq` b `seq` c `seq` ()
211-
rnf GhcVersionMismatch{} = rnf runTime
212195

213196
instance Hashable HscEnvEq where
214197
hashWithSalt s (HscEnvEq a _b _c) = hashWithSalt s a
215-
hashWithSalt salt GhcVersionMismatch{..} = hashWithSalt salt (compileTime, runTime)
216198

217199
-- Fake instance needed to persuade Shake to accept this type as a key.
218200
-- No harm done as ghcide never persists these keys currently

stack-ghc-lib.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extra-deps:
1313
- regex-base-0.94.0.0
1414
- regex-tdfa-1.3.1.0
1515
- haddock-library-1.8.0
16-
- ghc-check-0.3.0.1
16+
- ghc-check-0.5.0.1
1717
nix:
1818
packages: [zlib]
1919
flags:

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ extra-deps:
1414
- parser-combinators-1.2.1
1515
- haddock-library-1.8.0
1616
- tasty-rerun-1.1.17
17-
- ghc-check-0.3.0.1
17+
- ghc-check-0.5.0.1
1818
nix:
1919
packages: [zlib]

stack810.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extra-deps:
77
- haskell-lsp-0.22.0.0
88
- haskell-lsp-types-0.22.0.0
99
- lsp-test-0.11.0.1
10-
- ghc-check-0.3.0.1
10+
- ghc-check-0.5.0.1
1111
- hie-bios-0.5.0
1212

1313
# for ghc-8.10

stack84.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extra-deps:
2222
- unordered-containers-0.2.10.0
2323
- file-embed-0.0.11.2
2424
- heaps-0.3.6.1
25-
- ghc-check-0.3.0.1
25+
- ghc-check-0.5.0.1
2626
# For tasty-retun
2727
- ansi-terminal-0.10.3
2828
- ansi-wl-pprint-0.6.9

stack88.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ extra-deps:
55
- haskell-lsp-0.22.0.0
66
- haskell-lsp-types-0.22.0.0
77
- lsp-test-0.11.0.1
8-
- ghc-check-0.3.0.1
8+
- ghc-check-0.5.0.1
99
- hie-bios-0.5.0
10+
1011
nix:
1112
packages: [zlib]

0 commit comments

Comments
 (0)