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 2 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 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


44 changes: 2 additions & 42 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
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
54 changes: 3 additions & 51 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ module Development.IDE.GHC.Compat.Core (
maxRefHoleFits,
maxValidHoleFits,
setOutputFile,
#if MIN_VERSION_ghc(8,8,0)
CommandLineOption,
#if !MIN_VERSION_ghc(9,2,0)
staticPlugins,
#endif
#endif
sPgm_F,
settings,
Expand Down Expand Up @@ -263,7 +261,7 @@ module Development.IDE.GHC.Compat.Core (
SrcLoc.noSrcSpan,
SrcLoc.noSrcLoc,
SrcLoc.noLoc,
#if !MIN_VERSION_ghc(8,10,0) && MIN_VERSION_ghc(8,8,0)
#if !MIN_VERSION_ghc(8,10,0)
SrcLoc.dL,
#endif
-- * Finder
Expand Down Expand Up @@ -734,19 +732,12 @@ import NameCache
import NameEnv
import NameSet
import Packages
#if MIN_VERSION_ghc(8,8,0)
import Panic hiding (try)
import qualified PlainPanic as Plain
#else
import Panic hiding (GhcException, try)
import qualified Panic as Plain
#endif
import Parser
import PatSyn
import RnFixity
#if MIN_VERSION_ghc(8,8,0)
import Plugins
#endif
import PprTyThing hiding (pprFamInst)
import PrelInfo
import PrelNames hiding (Unique, printName)
Expand Down Expand Up @@ -791,10 +782,8 @@ import SrcLoc (RealLocated,
#endif


#if !MIN_VERSION_ghc(8,8,0)
import Data.List (isSuffixOf)
import System.FilePath
#endif


#if MIN_VERSION_ghc(9,2,0)
Expand Down Expand Up @@ -931,49 +920,22 @@ pattern L l a <- GHC.L (getLoc -> l) a
{-# COMPLETE L #-}
#endif

#elif MIN_VERSION_ghc(8,8,0)
#else
type HasSrcSpan = SrcLoc.HasSrcSpan
getLoc :: SrcLoc.HasSrcSpan a => a -> SrcLoc.SrcSpan
getLoc = SrcLoc.getLoc

#else

class HasSrcSpan a where
getLoc :: a -> SrcSpan
instance HasSrcSpan Name where
getLoc = nameSrcSpan
instance HasSrcSpan (SrcLoc.GenLocated SrcSpan a) where
getLoc = SrcLoc.getLoc

#endif

getRealSrcSpan :: SrcLoc.RealLocated a -> SrcLoc.RealSrcSpan
#if !MIN_VERSION_ghc(8,8,0)
getRealSrcSpan = SrcLoc.getLoc
#else
getRealSrcSpan = SrcLoc.getRealSrcSpan
#endif


-- | Add the @-boot@ suffix to all output file paths associated with the
-- module, not including the input file itself
addBootSuffixLocnOut :: GHC.ModLocation -> GHC.ModLocation
#if !MIN_VERSION_ghc(8,8,0)
addBootSuffixLocnOut locn
= locn { Module.ml_hi_file = Module.addBootSuffix (Module.ml_hi_file locn)
, Module.ml_obj_file = Module.addBootSuffix (Module.ml_obj_file locn)
}
#else
addBootSuffixLocnOut = Module.addBootSuffixLocnOut
#endif


dataConExTyCoVars :: DataCon -> [TyCoVar]
#if __GLASGOW_HASKELL__ >= 808
dataConExTyCoVars = DataCon.dataConExTyCoVars
#else
dataConExTyCoVars = DataCon.dataConExTyVars
#endif

#if !MIN_VERSION_ghc(9,0,0)
-- Linear Haskell
Expand All @@ -987,7 +949,7 @@ unrestricted = id

mkVisFunTys :: [Scaled Type] -> Type -> Type
mkVisFunTys =
#if __GLASGOW_HASKELL__ <= 808
#if __GLASGOW_HASKELL__ == 808
mkFunTys
#else
TcType.mkVisFunTys
Expand Down Expand Up @@ -1031,25 +993,15 @@ noExtField = GHC.noExt
#endif

ml_hie_file :: GHC.ModLocation -> FilePath
#if !MIN_VERSION_ghc(8,8,0)
ml_hie_file ml
| "boot" `isSuffixOf ` Module.ml_hi_file ml = Module.ml_hi_file ml -<.> ".hie-boot"
| otherwise = Module.ml_hi_file ml -<.> ".hie"
#else
ml_hie_file = Module.ml_hie_file
#endif

#if !MIN_VERSION_ghc(9,0,0)
pattern NotBoot, IsBoot :: IsBootInterface
pattern NotBoot = False
pattern IsBoot = True
#endif

#if MIN_VERSION_ghc(8,8,0)
type PlainGhcException = Plain.PlainGhcException
#else
type PlainGhcException = Plain.GhcException
#endif

#if MIN_VERSION_ghc(9,0,0)
-- This is from the old api, but it still simplifies
Expand Down
12 changes: 1 addition & 11 deletions ghcide/src/Development/IDE/GHC/Compat/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
module Development.IDE.GHC.Compat.Plugins (
Plugin(..),
defaultPlugin,
#if __GLASGOW_HASKELL__ >= 808
PluginWithArgs(..),
#endif
applyPluginsParsedResultAction,
initializePlugins,

-- * Static plugins
#if MIN_VERSION_ghc(8,8,0)
StaticPlugin(..),
hsc_static_plugins,
#endif
) where

#if MIN_VERSION_ghc(9,0,0)
Expand All @@ -31,13 +27,9 @@ import GHC.Driver.Plugins (ParsedResult (..),
staticPlugins)
#endif
import qualified GHC.Runtime.Loader as Loader
#elif MIN_VERSION_ghc(8,8,0)
import qualified DynamicLoading as Loader
import Plugins
#else
import qualified DynamicLoading as Loader
import Plugins (Plugin (..), defaultPlugin,
withPlugins)
import Plugins
#endif
import Development.IDE.GHC.Compat.Core
import Development.IDE.GHC.Compat.Env (hscSetFlags, hsc_dflags)
Expand Down Expand Up @@ -76,7 +68,6 @@ initializePlugins env = do
#endif


#if MIN_VERSION_ghc(8,8,0)
hsc_static_plugins :: HscEnv -> [StaticPlugin]
#if MIN_VERSION_ghc(9,3,0)
hsc_static_plugins = staticPlugins . Env.hsc_plugins
Expand All @@ -85,4 +76,3 @@ hsc_static_plugins = Env.hsc_static_plugins
#else
hsc_static_plugins = staticPlugins . hsc_dflags
#endif
#endif
Loading