on master help sign in
IDE GHC 8.6 Compatibilty (#1148)

* Rename the #ifdef for GHC_STABLE * More CPP required for GHC stable * Add a compatibility wrapper for HIE functionality which is new in GHC HEAD * HLint ignores * Finish the dummy implementations * Add a bazel build for the ide-core library against GHC

commit8158587b89ca1a19f64a3e7a7661d71e5017d1c4 authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateWed 15 May 2019, 11:21 (7 years ago) parent849908d
8 files changed+99−37
BUILD.bazel+45−26 src/Development/IDE/Compat.hs+38 src/Development/IDE/Functions/AtPoint.hs+1−1 src/Development/IDE/Functions/CPP.hs+5−1 src/Development/IDE/Functions/Compile.hs+5−7 src/Development/IDE/State/RuleTypes.hs+1−1 src/Development/IDE/State/Rules.hs+1−1 src/Development/IDE/UtilGHC.hs+3
BUILD.bazel+45−26
@@ -3,37 +3,56 @@
33
44load("//bazel_tools:haskell.bzl", "da_haskell_library")
55
6+depends = [
7+ "aeson",
8+ "base",
9+ "binary",
10+ "bytestring",
11+ "containers",
12+ "deepseq",
13+ "directory",
14+ "either",
15+ "extra",
16+ "filepath",
17+ "hashable",
18+ "haskell-lsp",
19+ "haskell-lsp-types",
20+ "mtl",
21+ "pretty",
22+ "safe-exceptions",
23+ "shake",
24+ "stm",
25+ "syb",
26+ "text",
27+ "time",
28+ "transformers",
29+ "uniplate",
30+ "unordered-containers",
31+ "uri-encode",
32+]
33+
634da_haskell_library(
735 name = "haskell-ide-core",
836 srcs = glob(["src/**/*.hs"]),
9− hazel_deps = [
10− "aeson",
11− "base",
12− "binary",
13− "bytestring",
14− "containers",
15− "deepseq",
16− "directory",
17− "either",
18− "extra",
19− "filepath",
37+ hazel_deps = depends + [
2038 "ghc-lib",
2139 "ghc-lib-parser",
22− "hashable",
23− "haskell-lsp",
24− "haskell-lsp-types",
25− "mtl",
26− "pretty",
27− "safe-exceptions",
28− "shake",
29− "stm",
30− "syb",
31− "text",
32− "time",
33− "transformers",
34− "uniplate",
35− "unordered-containers",
36− "uri-encode",
40+ ],
41+ src_strip_prefix = "src",
42+ visibility = ["//visibility:public"],
43+ deps = [
44+ "//libs-haskell/prettyprinter-syntax",
45+ ],
46+)
47+
48+da_haskell_library(
49+ name = "haskell-ide-core-public",
50+ srcs = glob(["src/**/*.hs"]),
51+ compiler_flags = ["-DGHC_STABLE"],
52+ hazel_deps = depends + [
53+ "ghc",
54+ "ghc-boot",
55+ "ghc-boot-th",
3756 ],
3857 src_strip_prefix = "src",
3958 visibility = ["//visibility:public"],
src/Development/IDE/Compat.hsnew file+38
@@ -0,0 +1,38 @@
1+-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+-- SPDX-License-Identifier: Apache-2.0
3+
4+{-# LANGUAGE CPP #-}
5+
6+-- | Attempt at hiding the GHC version differences we can.
7+module Development.IDE.Compat(
8+ HieFile(..),
9+ mkHieFile,
10+ writeHieFile,
11+ readHieFile
12+ ) where
13+
14+#ifndef GHC_STABLE
15+import HieBin
16+import HieAst
17+import HieTypes
18+#else
19+
20+import GHC
21+import GhcPlugins
22+import NameCache
23+import Avail
24+import TcRnTypes
25+
26+
27+mkHieFile :: ModSummary -> TcGblEnv -> RenamedSource -> Hsc HieFile
28+mkHieFile _ _ _ = return (HieFile () [])
29+
30+writeHieFile :: FilePath -> HieFile -> IO ()
31+writeHieFile _ _ = return ()
32+
33+readHieFile :: NameCache -> FilePath -> IO (HieFile, ())
34+readHieFile _ _ = return (HieFile () [], ())
35+
36+data HieFile = HieFile {hie_module :: (), hie_exports :: [AvailInfo]}
37+
38+#endif
src/Development/IDE/Functions/AtPoint.hs+1−1
@@ -16,6 +16,7 @@ import Development.IDE.Orphans()
1616-- DAML compiler and infrastructure
1717import Development.Shake
1818import Development.IDE.UtilGHC
19+import Development.IDE.Compat
1920import Development.IDE.State.Shake
2021import Development.IDE.State.RuleTypes
2122import Development.IDE.Types.Diagnostics
@@ -27,7 +28,6 @@ import Development.IDE.Types.SpanInfo as SpanInfo
2728import Avail
2829import GHC
2930import DynFlags
30−import HieTypes
3131import FastString
3232import Name
3333import Outputable hiding ((<>))
src/Development/IDE/Functions/CPP.hs+5−1
@@ -49,7 +49,11 @@ doCpp dflags raw input_fn output_fn = do
4949 let verbFlags = getVerbFlags dflags
5050
5151 let cpp_prog args | raw = SysTools.runCpp dflags args
52− | otherwise = SysTools.runCc Nothing dflags (SysTools.Option "-E" : args)
52+ | otherwise = SysTools.runCc
53+#ifndef GHC_STABLE
54+ Nothing
55+#endif
56+ dflags (SysTools.Option "-E" : args)
5357
5458 let target_defs = [] {-
5559 [ "-D" ++ HOST_OS ++ "_BUILD_OS",
src/Development/IDE/Functions/Compile.hs+5−7
@@ -28,11 +28,9 @@ import qualified Development.IDE.Functions.FindImports as FindImports
2828import Development.IDE.Functions.GHCError
2929import Development.IDE.Functions.SpanInfo
3030import Development.IDE.UtilGHC
31+import Development.IDE.Compat
3132import Development.IDE.Types.Options
3233
33−import HieBin
34−import HieAst
35−
3634import GHC hiding (parseModule, typecheckModule)
3735import qualified Parser
3836import Lexer
@@ -410,7 +408,7 @@ getModSummaryFromBuffer fp (contents, fileDate) dflags parsed = do
410408 { ml_hs_file = Just fp
411409 , ml_hi_file = replaceExtension fp "hi"
412410 , ml_obj_file = replaceExtension fp "o"
413−#ifndef USE_GHC
411+#ifndef GHC_STABLE
414412 , ml_hie_file = replaceExtension fp "hie"
415413#endif
416414 -- This does not consider the dflags configuration
@@ -431,7 +429,7 @@ getModSummaryFromBuffer fp (contents, fileDate) dflags parsed = do
431429 , ms_hsc_src = HsSrcFile
432430 , ms_obj_date = Nothing
433431 , ms_iface_date = Nothing
434−#ifndef USE_GHC
432+#ifndef GHC_STABLE
435433 , ms_hie_date = Nothing
436434#endif
437435 , ms_srcimps = [] -- source imports are not allowed
@@ -465,8 +463,8 @@ parseFileContents preprocessor filename (time, contents) = do
465463 return (contents, dflags)
466464
467465 case unP Parser.parseModule (mkPState dflags contents loc) of
468−#ifdef USE_GHC
469− PFailed _ logMsg msgErr ->
466+#ifdef GHC_STABLE
467+ PFailed _ locErr msgErr ->
470468 Ex.throwE $ mkErrorDoc dflags locErr msgErr
471469#else
472470 PFailed s ->
src/Development/IDE/State/RuleTypes.hs+1−1
@@ -24,7 +24,7 @@ import Development.Shake hiding (Env, newCache)
2424import GHC.Generics (Generic)
2525
2626import GHC
27−import HieTypes
27+import Development.IDE.Compat
2828import Module
2929
3030import Development.IDE.Types.SpanInfo
src/Development/IDE/State/Rules.hs+1−1
@@ -46,7 +46,7 @@ import Development.IDE.Types.LSP as Compiler
4646import Development.IDE.State.RuleTypes
4747
4848import GHC
49−import HieBin
49+import Development.IDE.Compat
5050import UniqSupply
5151import Module as M
5252import NameCache
src/Development/IDE/UtilGHC.hs+3
@@ -2,6 +2,7 @@
22-- SPDX-License-Identifier: Apache-2.0
33
44{-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
5+{-# LANGUAGE CPP #-}
56
67-- | GHC utility functions. Importantly, code using our GHC should never:
78--
@@ -129,7 +130,9 @@ fakeDynFlags = defaultDynFlags settings ([], [])
129130 {pc_DYNAMIC_BY_DEFAULT = False
130131 ,pc_WORD_SIZE = 8
131132 }
133+#ifndef GHC_STABLE
132134 ,sIntegerLibraryType = IntegerSimple
135+#endif
133136 ,sProjectVersion = cProjectVersion
134137 ,sProgramName = "ghc"
135138 ,sOpt_P_fingerprint = fingerprint0