Skip to content

Cleanup GHC macros (because min version is 8.8.4) #3281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ To create binaries:
* `nix build .#haskell-language-server-884` - GHC 8.8.4
* `nix build .#haskell-language-server-901` - GHC 9.0.1

GHC 8.6.5 is not supported here because `nixpkgs-unstable` no longer maintains the corresponding packages set.

## Testing

The tests make use of the [Tasty](https://github.com/feuerbach/tasty) test framework.
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/plugin-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ And here is the gist of the algorithm:

## Setup

To get started, let’s fetch the HLS repo and build it. You need at least GHC 8.6 for this:
To get started, let’s fetch the HLS repo and build it. You need at least GHC 8.8 for this:

```
git clone --recursive http://github.com/haskell/haskell-language-server hls
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Homebrew users can install `haskell-language-server` using the following command
brew install haskell-language-server
```

This formula contains HLS binaries compiled with GHC versions available via Homebrew; at the moment those are: 8.6.5, 8.8.4, 8.10.7.
This formula contains HLS binaries compiled with GHC versions available via Homebrew; at the moment those are: 8.8.4, 8.10.7.

You need to provide your own GHC/Cabal/Stack as required by your project, possibly via Homebrew.

Expand Down
2 changes: 1 addition & 1 deletion ghcide-bench/ghcide-bench.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ synopsis: An LSP client for running performance experiments on HLS
description: An LSP client for running performance experiments on HLS
homepage: https://github.com/haskell/haskell-language-server/tree/master/ghcide#readme
bug-reports: https://github.com/haskell/haskell-language-server/issues
tested-with: GHC == 8.6.5 || == 8.8.4 || == 8.10.7 || == 9.0.2 || == 9.2.3 || == 9.2.4
tested-with: GHC == 8.8.4 || == 8.10.7 || == 9.0.2 || == 9.2.3 || == 9.2.4

source-repository head
type: git
Expand Down
2 changes: 1 addition & 1 deletion ghcide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ If you can't get `ghcide` working outside the editor, see [this setup troublesho

### Optimal project setup

`ghcide` has been designed to handle projects with hundreds or thousands of modules. If `ghci` can handle it, then `ghcide` should be able to handle it. The only caveat is that this currently requires GHC >= 8.6, and that the first time a module is loaded in the editor will trigger generation of support files in the background if those do not already exist.
`ghcide` has been designed to handle projects with hundreds or thousands of modules. If `ghci` can handle it, then `ghcide` should be able to handle it. The only caveat is that this currently requires GHC >= 8.8, and that the first time a module is loaded in the editor will trigger generation of support files in the background if those do not already exist.

### Using with VS Code

Expand Down
4 changes: 2 additions & 2 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ library
unliftio-core,
ghc-boot-th,
ghc-boot,
ghc >= 8.6,
ghc >= 8.8,
ghc-check >=0.5.0.8,
ghc-paths,
cryptohash-sha1 >=0.11.100 && <0.12,
Expand Down Expand Up @@ -363,7 +363,7 @@ test-suite ghcide-tests
text,
text-rope,
unordered-containers,
if (impl(ghc >= 8.6) && impl(ghc < 9.2))
if impl(ghc < 9.2)
build-depends:
record-dot-preprocessor,
record-hasfield
Expand Down
2 changes: 0 additions & 2 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,7 @@ getModSummaryFromImports env fp modTime contents = do
msrModSummary =
ModSummary
{ ms_mod = modl
#if MIN_VERSION_ghc(8,8,0)
, ms_hie_date = Nothing
#endif
#if MIN_VERSION_ghc(9,3,0)
, ms_dyn_obj_date = Nothing
, ms_ghc_prim_import = ghc_prim_import
Expand Down
3 changes: 0 additions & 3 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ module Development.IDE.Core.Rules(
DisplayTHWarning(..),
) where

#if !MIN_VERSION_ghc(8,8,0)
import Control.Applicative (liftA2)
#endif
import Control.Concurrent.Async (concurrently)
import Control.Concurrent.Strict
import Control.DeepSeq
Expand Down
16 changes: 4 additions & 12 deletions ghcide/src/Development/IDE/Core/Tracing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,16 @@ import OpenTelemetry.Eventlog (SpanInFlight (..), addEvent,
beginSpan, endSpan, setTag,
withSpan)

#if MIN_VERSION_ghc(8,8,0)
otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
otTracedGarbageCollection :: (MonadMask f, MonadIO f, Show a) => ByteString -> f [a] -> f [a]
withEventTrace :: (MonadMask m, MonadIO m) => String -> ((ByteString -> m ()) -> m a) -> m a
#else
otTracedProvider :: MonadUnliftIO m => PluginId -> String -> m a -> m a
otTracedGarbageCollection :: (MonadMask f, MonadIO f, Show a) => String -> f [a] -> f [a]
withEventTrace :: (MonadMask m, MonadIO m) => String -> ((ByteString -> m ()) -> m a) -> m a
#endif

withTrace :: (MonadMask m, MonadIO m) =>
String -> ((String -> String -> m ()) -> m a) -> m a
withTrace :: (MonadMask m, MonadIO m) => String -> ((String -> String -> m ()) -> m a) -> m a
withTrace name act
| userTracingEnabled
= withSpan (fromString name) $ \sp -> do
let setSpan' k v = setTag sp (fromString k) (fromString v)
act setSpan'
| otherwise = act (\_ _ -> pure ())

withEventTrace :: (MonadMask m, MonadIO m) => String -> ((ByteString -> m ()) -> m a) -> m a
withEventTrace name act
| userTracingEnabled
= withSpan (fromString name) $ \sp -> do
Expand Down Expand Up @@ -125,6 +116,7 @@ otTracedAction key file mode result act
(\sp -> act (liftIO . setTag sp "diagnostics" . encodeUtf8 . showDiagnostics ))
| otherwise = act (\_ -> return ())

otTracedGarbageCollection :: (MonadMask f, MonadIO f, Show a) => ByteString -> f [a] -> f [a]
otTracedGarbageCollection label act
| userTracingEnabled = fst <$>
generalBracket
Expand All @@ -138,6 +130,7 @@ otTracedGarbageCollection label act
(const act)
| otherwise = act

otTracedProvider :: MonadUnliftIO m => PluginId -> ByteString -> m a -> m a
otTracedProvider (PluginId pluginName) provider act
| userTracingEnabled = do
runInIO <- askRunInIO
Expand All @@ -146,4 +139,3 @@ otTracedProvider (PluginId pluginName) provider act
runInIO act
| otherwise = act


49 changes: 3 additions & 46 deletions ghcide/src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,8 @@ import DynFlags hiding (ExposePackage)
import HscTypes
import MkIface hiding (writeIfaceFile)

#if MIN_VERSION_ghc(8,8,0)
import StringBuffer (hPutStringBuffer)
#endif
import qualified SysTools

#if !MIN_VERSION_ghc(8,8,0)
import qualified EnumSet
import SrcLoc (RealLocated)

import Foreign.ForeignPtr
import System.IO
#endif
#endif

import Compat.HieAst (enrichHie)
Expand Down Expand Up @@ -385,13 +375,6 @@ corePrepExpr _ = GHC.corePrepExpr
simplifyExpr df _ = GHC.simplifyExpr df
#endif

#if !MIN_VERSION_ghc(8,8,0)
hPutStringBuffer :: Handle -> StringBuffer -> IO ()
hPutStringBuffer hdl (StringBuffer buf len cur)
= withForeignPtr (plusForeignPtr buf cur) $ \ptr ->
hPutBuf hdl ptr len
#endif

#if MIN_VERSION_ghc(9,2,0)
type ErrMsg = MsgEnvelope DecoratedSDoc
#endif
Expand Down Expand Up @@ -445,12 +428,7 @@ hieExportNames = nameListFromAvails . hie_exports
type NameCacheUpdater = NameCache
#else
upNameCache :: IORef NameCache -> (NameCache -> (NameCache, c)) -> IO c
#if MIN_VERSION_ghc(8,8,0)
upNameCache = updNameCache
#else
upNameCache ref upd_fn
= atomicModifyIORef' ref upd_fn
#endif
#endif

#if !MIN_VERSION_ghc(9,0,1)
Expand Down Expand Up @@ -480,27 +458,15 @@ addIncludePathsQuote path x = x{includePaths = f $ includePaths x}
where f i = i{includePathsQuote = path : includePathsQuote i}

setHieDir :: FilePath -> DynFlags -> DynFlags
setHieDir _f d =
#if MIN_VERSION_ghc(8,8,0)
d { hieDir = Just _f}
#else
d
#endif
setHieDir _f d = d { hieDir = Just _f}

dontWriteHieFiles :: DynFlags -> DynFlags
dontWriteHieFiles d =
#if MIN_VERSION_ghc(8,8,0)
gopt_unset d Opt_WriteHie
#else
d
#endif
dontWriteHieFiles d = gopt_unset d Opt_WriteHie

setUpTypedHoles ::DynFlags -> DynFlags
setUpTypedHoles df
= flip gopt_unset Opt_AbstractRefHoleFits -- too spammy
#if MIN_VERSION_ghc(8,8,0)
$ flip gopt_unset Opt_ShowDocsOfHoleFits -- not used
#endif
$ flip gopt_unset Opt_ShowMatchesOfHoleFits -- nice but broken (forgets module qualifiers)
$ flip gopt_unset Opt_ShowProvOfHoleFits -- not used
$ flip gopt_unset Opt_ShowTypeAppOfHoleFits -- not used
Expand Down Expand Up @@ -533,12 +499,6 @@ disableWarningsAsErrors :: DynFlags -> DynFlags
disableWarningsAsErrors df =
flip gopt_unset Opt_WarnIsError $ foldl' wopt_unset_fatal df [toEnum 0 ..]

#if !MIN_VERSION_ghc(8,8,0)
wopt_unset_fatal :: DynFlags -> WarningFlag -> DynFlags
wopt_unset_fatal dfs f
= dfs { fatalWarningFlags = EnumSet.delete f (fatalWarningFlags dfs) }
#endif

isQualifiedImport :: ImportDecl a -> Bool
#if MIN_VERSION_ghc(8,10,0)
isQualifiedImport ImportDecl{ideclQualified = NotQualified} = False
Expand Down Expand Up @@ -606,8 +566,7 @@ generatedNodeInfo = sourceNodeInfo -- before ghc 9.0, we don't distinguish the s
#endif

data GhcVersion
= GHC86
| GHC88
= GHC88
| GHC810
| GHC90
| GHC92
Expand All @@ -628,8 +587,6 @@ ghcVersion = GHC90
ghcVersion = GHC810
#elif MIN_VERSION_GLASGOW_HASKELL(8,8,0,0)
ghcVersion = GHC88
#elif MIN_VERSION_GLASGOW_HASKELL(8,6,0,0)
ghcVersion = GHC86
#endif

runUnlit :: Logger -> DynFlags -> [Option] -> IO ()
Expand Down
21 changes: 5 additions & 16 deletions ghcide/src/Development/IDE/GHC/Compat/CPP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ module Development.IDE.GHC.Compat.CPP (
doCpp
) where

import FileCleanup
import Packages
import Panic
import SysTools
#if MIN_VERSION_ghc(8,8,2)
import LlvmCodeGen (llvmVersionList)
#elif MIN_VERSION_ghc(8,8,0)
import LlvmCodeGen (LlvmVersion (..))
#endif
import Control.Monad
import Data.List (intercalate)
import Data.Maybe
import Data.Version
import DynFlags
import FileCleanup
import LlvmCodeGen (llvmVersionList)
import Module (rtsUnitId, toInstalledUnitId)
import Packages
import Panic
import System.Directory
import System.FilePath
import System.Info
import SysTools

import Development.IDE.GHC.Compat as Compat

Expand Down Expand Up @@ -136,16 +132,9 @@ getBackendDefs :: DynFlags -> IO [String]
getBackendDefs dflags | hscTarget dflags == HscLlvm = do
llvmVer <- figureLlvmVersion dflags
return $ case llvmVer of
#if MIN_VERSION_ghc(8,8,2)
Just v
| [m] <- llvmVersionList v -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (m, 0) ]
| m:n:_ <- llvmVersionList v -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (m, n) ]
#elif MIN_VERSION_ghc(8,8,0)
Just (LlvmVersion n) -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (n,0) ]
Just (LlvmVersionOld m n) -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (m,n) ]
#else
Just n -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format n ]
#endif
_ -> []
where
format (major, minor)
Expand Down
Loading