Skip to content

Commit

Permalink
IDE GHC 8.6 Compatibilty (digital-asset#1148)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
neil-da authored May 15, 2019
1 parent e6c7421 commit abb8af6
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 38 deletions.
9 changes: 8 additions & 1 deletion .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@
- {name: ViewPatterns, within: []}

# Shady extensions
- {name: CPP, within: [DA.Sdk.Cli.System, DA.Sdk.Cli.Version, DAML.Assistant.Install.Path, Development.IDE.Functions.Compile]}
- name: CPP
within:
- DA.Sdk.Cli.System
- DA.Sdk.Cli.Version
- DAML.Assistant.Install.Path
- Development.IDE.Functions.Compile
- Development.IDE.UtilGHC
- Development.IDE.Compat
- {name: ImplicitParams, within: []}

- flags:
Expand Down
71 changes: 45 additions & 26 deletions compiler/haskell-ide-core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,56 @@

load("//bazel_tools:haskell.bzl", "da_haskell_library")

depends = [
"aeson",
"base",
"binary",
"bytestring",
"containers",
"deepseq",
"directory",
"either",
"extra",
"filepath",
"hashable",
"haskell-lsp",
"haskell-lsp-types",
"mtl",
"pretty",
"safe-exceptions",
"shake",
"stm",
"syb",
"text",
"time",
"transformers",
"uniplate",
"unordered-containers",
"uri-encode",
]

da_haskell_library(
name = "haskell-ide-core",
srcs = glob(["src/**/*.hs"]),
hazel_deps = [
"aeson",
"base",
"binary",
"bytestring",
"containers",
"deepseq",
"directory",
"either",
"extra",
"filepath",
hazel_deps = depends + [
"ghc-lib",
"ghc-lib-parser",
"hashable",
"haskell-lsp",
"haskell-lsp-types",
"mtl",
"pretty",
"safe-exceptions",
"shake",
"stm",
"syb",
"text",
"time",
"transformers",
"uniplate",
"unordered-containers",
"uri-encode",
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
"//libs-haskell/prettyprinter-syntax",
],
)

da_haskell_library(
name = "haskell-ide-core-public",
srcs = glob(["src/**/*.hs"]),
compiler_flags = ["-DGHC_STABLE"],
hazel_deps = depends + [
"ghc",
"ghc-boot",
"ghc-boot-th",
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
Expand Down
38 changes: 38 additions & 0 deletions compiler/haskell-ide-core/src/Development/IDE/Compat.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE CPP #-}

-- | Attempt at hiding the GHC version differences we can.
module Development.IDE.Compat(
HieFile(..),
mkHieFile,
writeHieFile,
readHieFile
) where

#ifndef GHC_STABLE
import HieBin
import HieAst
import HieTypes
#else

import GHC
import GhcPlugins
import NameCache
import Avail
import TcRnTypes


mkHieFile :: ModSummary -> TcGblEnv -> RenamedSource -> Hsc HieFile
mkHieFile _ _ _ = return (HieFile () [])

writeHieFile :: FilePath -> HieFile -> IO ()
writeHieFile _ _ = return ()

readHieFile :: NameCache -> FilePath -> IO (HieFile, ())
readHieFile _ _ = return (HieFile () [], ())

data HieFile = HieFile {hie_module :: (), hie_exports :: [AvailInfo]}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Development.IDE.Orphans()
-- DAML compiler and infrastructure
import Development.Shake
import Development.IDE.UtilGHC
import Development.IDE.Compat
import Development.IDE.State.Shake
import Development.IDE.State.RuleTypes
import Development.IDE.Types.Diagnostics
Expand All @@ -27,7 +28,6 @@ import Development.IDE.Types.SpanInfo as SpanInfo
import Avail
import GHC
import DynFlags
import HieTypes
import FastString
import Name
import Outputable hiding ((<>))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ doCpp dflags raw input_fn output_fn = do
let verbFlags = getVerbFlags dflags

let cpp_prog args | raw = SysTools.runCpp dflags args
| otherwise = SysTools.runCc Nothing dflags (SysTools.Option "-E" : args)
| otherwise = SysTools.runCc
#ifndef GHC_STABLE
Nothing
#endif
dflags (SysTools.Option "-E" : args)

let target_defs = [] {-
[ "-D" ++ HOST_OS ++ "_BUILD_OS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ import qualified Development.IDE.Functions.FindImports as FindImports
import Development.IDE.Functions.GHCError
import Development.IDE.Functions.SpanInfo
import Development.IDE.UtilGHC
import Development.IDE.Compat
import Development.IDE.Types.Options

import HieBin
import HieAst

import GHC hiding (parseModule, typecheckModule)
import qualified Parser
import Lexer
Expand Down Expand Up @@ -410,7 +408,7 @@ getModSummaryFromBuffer fp (contents, fileDate) dflags parsed = do
{ ml_hs_file = Just fp
, ml_hi_file = replaceExtension fp "hi"
, ml_obj_file = replaceExtension fp "o"
#ifndef USE_GHC
#ifndef GHC_STABLE
, ml_hie_file = replaceExtension fp "hie"
#endif
-- This does not consider the dflags configuration
Expand All @@ -431,7 +429,7 @@ getModSummaryFromBuffer fp (contents, fileDate) dflags parsed = do
, ms_hsc_src = HsSrcFile
, ms_obj_date = Nothing
, ms_iface_date = Nothing
#ifndef USE_GHC
#ifndef GHC_STABLE
, ms_hie_date = Nothing
#endif
, ms_srcimps = [] -- source imports are not allowed
Expand Down Expand Up @@ -465,8 +463,8 @@ parseFileContents preprocessor filename (time, contents) = do
return (contents, dflags)

case unP Parser.parseModule (mkPState dflags contents loc) of
#ifdef USE_GHC
PFailed _ logMsg msgErr ->
#ifdef GHC_STABLE
PFailed _ locErr msgErr ->
Ex.throwE $ mkErrorDoc dflags locErr msgErr
#else
PFailed s ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Development.Shake hiding (Env, newCache)
import GHC.Generics (Generic)

import GHC
import HieTypes
import Development.IDE.Compat
import Module

import Development.IDE.Types.SpanInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Development.IDE.Types.LSP as Compiler
import Development.IDE.State.RuleTypes

import GHC
import HieBin
import Development.IDE.Compat
import UniqSupply
import Module as M
import NameCache
Expand Down
3 changes: 3 additions & 0 deletions compiler/haskell-ide-core/src/Development/IDE/UtilGHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-- SPDX-License-Identifier: Apache-2.0

{-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
{-# LANGUAGE CPP #-}

-- | GHC utility functions. Importantly, code using our GHC should never:
--
Expand Down Expand Up @@ -129,7 +130,9 @@ fakeDynFlags = defaultDynFlags settings ([], [])
{pc_DYNAMIC_BY_DEFAULT = False
,pc_WORD_SIZE = 8
}
#ifndef GHC_STABLE
,sIntegerLibraryType = IntegerSimple
#endif
,sProjectVersion = cProjectVersion
,sProgramName = "ghc"
,sOpt_P_fingerprint = fingerprint0
Expand Down

0 comments on commit abb8af6

Please sign in to comment.