Skip to content

Cleanup cabal files, ghc compat code, fix ghc warnings #4222

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 9 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 3 additions & 17 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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 ==9.8.2 || ==9.6.4 || ==9.4.8 || ==9.2.8
tested-with: GHC ==9.8.2 || ==9.6.5 || ==9.4.8 || ==9.2.8
extra-source-files:
CHANGELOG.md
README.md
Expand Down Expand Up @@ -98,7 +98,6 @@ library
, prettyprinter-ansi-terminal
, random
, regex-tdfa >=1.3.1.0
, row-types
, safe-exceptions
, sorted-list
, sqlite-simple
Expand Down Expand Up @@ -272,25 +271,12 @@ library ghcide-test-utils
visibility: public
default-language: GHC2021

hs-source-dirs: test/src test/cabal
hs-source-dirs: test/cabal
exposed-modules:
Development.IDE.Test.Runfiles

build-depends:
aeson,
base > 4.9 && < 5,
containers,
data-default,
directory,
extra,
filepath,
ghcide,
lsp-types,
hls-plugin-api,
lens,
lsp-test ^>= 0.17,
tasty-hunit >= 0.10,
text,
base > 4.9 && < 5

default-extensions:
LambdaCase
Expand Down
6 changes: 2 additions & 4 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import qualified Data.Text as T
import Data.Time.Clock
import Data.Version
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake hiding (Log, Priority,
knownTargets, withHieDb)
import Development.IDE.Core.Shake hiding (Log, knownTargets,
withHieDb)
import qualified Development.IDE.GHC.Compat as Compat
import Development.IDE.GHC.Compat.Core hiding (Target,
TargetFile, TargetModule,
Expand All @@ -70,7 +70,6 @@ import Development.IDE.Types.Location
import Development.IDE.Types.Options
import GHC.Check
import qualified HIE.Bios as HieBios
import qualified HIE.Bios.Cradle as HieBios
import HIE.Bios.Environment hiding (getCacheDir)
import HIE.Bios.Types hiding (Log)
import qualified HIE.Bios.Types as HieBios
Expand Down Expand Up @@ -125,7 +124,6 @@ import qualified Data.Set as OS
import GHC.Data.Bag
import GHC.Driver.Env (hsc_all_home_unit_ids)
import GHC.Driver.Errors.Types
import GHC.Driver.Make (checkHomeUnitsClosed)
import GHC.Types.Error (errMsgDiagnostic,
singleMessage)
import GHC.Unit.State
Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ parseHeader dflags filename contents = do
PFailedWithErrorMessages msgs ->
throwE $ diagFromErrMsgs sourceParser dflags $ msgs dflags
POk pst rdr_module -> do
let (warns, errs) = renderMessages $ getPsMessages pst dflags
let (warns, errs) = renderMessages $ getPsMessages pst

-- Just because we got a `POk`, it doesn't mean there
-- weren't errors! To clarify, the GHC parser
Expand Down Expand Up @@ -1301,7 +1301,7 @@ parseFileContents env customPreprocessor filename ms = do
POk pst rdr_module ->
let
hpm_annotations = mkApiAnns pst
psMessages = getPsMessages pst dflags
psMessages = getPsMessages pst
in
do
let IdePreprocessedSource preproc_warns errs parsed = customPreprocessor rdr_module
Expand All @@ -1310,7 +1310,7 @@ parseFileContents env customPreprocessor filename ms = do
throwE $ diagFromStrings sourceParser DiagnosticSeverity_Error errs

let preproc_warnings = diagFromStrings sourceParser DiagnosticSeverity_Warning preproc_warns
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env dflags ms hpm_annotations parsed psMessages
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env ms hpm_annotations parsed psMessages
let (warns, errors) = renderMessages msgs

-- Just because we got a `POk`, it doesn't mean there
Expand Down
5 changes: 1 addition & 4 deletions ghcide/src/Development/IDE/Core/FileStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module Development.IDE.Core.FileStore(
Log(..)
) where

import Control.Concurrent.STM.Stats (STM, atomically,
modifyTVar')
import Control.Concurrent.STM.Stats (STM, atomically)
import Control.Concurrent.STM.TQueue (writeTQueue)
import Control.Exception
import Control.Monad.Extra
Expand All @@ -32,10 +31,8 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HashMap
import Data.IORef
import Data.List (foldl')
import qualified Data.Text as T
import qualified Data.Text as Text
import qualified Data.Text.Utf16.Rope as Rope
import Data.Time
import Data.Time.Clock.POSIX
import Development.IDE.Core.FileUtils
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Control.Monad.IO.Class
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Proxy
import qualified Data.Text as T
import Development.IDE.Graph

import Control.Concurrent.STM.Stats (atomically,
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Core/PositionMapping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Control.Monad
import Data.Algorithm.Diff
import Data.Bifunctor
import Data.List
import Data.Row
import qualified Data.Text as T
import qualified Data.Vector.Unboxed as V
import qualified Language.LSP.Protocol.Lens as L
Expand Down
28 changes: 5 additions & 23 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module Development.IDE.Core.Rules(
getHieAstsRule,
getBindingsRule,
needsCompilationRule,
computeLinkableTypeForDynFlags,
generateCoreRule,
getImportMapRule,
regenerateHiFile,
Expand All @@ -58,7 +57,6 @@ module Development.IDE.Core.Rules(
) where

import Control.Applicative
import Control.Concurrent.Async (concurrently)
import Control.Concurrent.STM.Stats (atomically)
import Control.Concurrent.STM.TVar
import Control.Concurrent.Strict
Expand Down Expand Up @@ -90,10 +88,8 @@ import Data.List.Extra (nubOrdOn)
import qualified Data.Map as M
import Data.Maybe
import Data.Proxy
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Utf16.Rope as Rope
import Data.Time (UTCTime (..))
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Data.Tuple.Extra
Expand Down Expand Up @@ -123,7 +119,6 @@ import Development.IDE.GHC.Compat hiding
import qualified Development.IDE.GHC.Compat as Compat hiding
(nest,
vcat)
import Development.IDE.GHC.Compat.Env
import qualified Development.IDE.GHC.Compat.Util as Util
import Development.IDE.GHC.Error
import Development.IDE.GHC.Util hiding
Expand Down Expand Up @@ -1148,36 +1143,23 @@ needsCompilationRule file = do
-- that we just threw away, and thus have to recompile all dependencies once
-- again, this time keeping the object code.
-- A file needs to be compiled if any file that depends on it uses TemplateHaskell or needs to be compiled
ms <- msrModSummary . fst <$> useWithStale_ GetModSummaryWithoutTimestamps file
(modsums,needsComps) <- liftA2
(,) (map (fmap (msrModSummary . fst)) <$> usesWithStale GetModSummaryWithoutTimestamps revdeps)
(uses NeedsCompilation revdeps)
pure $ computeLinkableType ms modsums (map join needsComps)
pure $ computeLinkableType modsums (map join needsComps)
pure (Just $ encodeLinkableType res, Just res)
where
computeLinkableType :: ModSummary -> [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType
computeLinkableType this deps xs
computeLinkableType :: [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType
computeLinkableType deps xs
| Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we
| Just BCOLinkable `elem` xs = Just this_type -- If any dependent needs bytecode, then we need to be compiled
| any (maybe False uses_th_qq) deps = Just this_type -- If any dependent needs TH, then we need to be compiled
| Just BCOLinkable `elem` xs = Just BCOLinkable -- If any dependent needs bytecode, then we need to be compiled
| any (maybe False uses_th_qq) deps = Just BCOLinkable -- If any dependent needs TH, then we need to be compiled
| otherwise = Nothing -- If none of these conditions are satisfied, we don't need to compile
where
this_type = computeLinkableTypeForDynFlags (ms_hspp_opts this)

uses_th_qq :: ModSummary -> Bool
uses_th_qq (ms_hspp_opts -> dflags) =
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags

-- | How should we compile this module?
-- (assuming we do in fact need to compile it).
-- Depends on whether it uses unboxed tuples or sums
computeLinkableTypeForDynFlags :: DynFlags -> LinkableType
computeLinkableTypeForDynFlags d
= BCOLinkable
where -- unboxed_tuples_or_sums is only used in GHC < 9.2
_unboxed_tuples_or_sums =
Copy link
Collaborator Author

@jhrcek jhrcek May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting simplification #1: this is unused on GHCs we support, which means this function doesn't depend on DynFlags and we can just hardcode BCOLinkable in bunch of places leading to bunch of simplifications in this and other modules.

Please search for 3 new hardcoded BCOLinkable occurrences to check if it makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems plausible!

xopt LangExt.UnboxedTuples d || xopt LangExt.UnboxedSums d

-- | Tracks which linkables are current, so we don't need to unload them
newtype CompiledLinkables = CompiledLinkables { getCompiledLinkables :: Var (ModuleEnv UTCTime) }
instance IsIdeGlobal CompiledLinkables
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ getStateKeys = (fmap.fmap) fst . atomically . ListT.toList . STM.listT . state

-- | Must be called in the 'Initialized' handler and only once
shakeSessionInit :: Recorder (WithPriority Log) -> IdeState -> IO ()
shakeSessionInit recorder ide@IdeState{..} = do
shakeSessionInit recorder IdeState{..} = do
-- Take a snapshot of the VFS - it should be empty as we've received no notifications
-- till now, but it can't hurt to be in sync with the `lsp` library.
vfs <- vfsSnapshot (lspEnv shakeExtras)
Expand Down
48 changes: 27 additions & 21 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ module Development.IDE.GHC.Compat.Core (
pattern ConPatIn,
conPatDetails,
mapConPatDetail,
#if MIN_VERSION_ghc(9,5,0)
mkVisFunTys,
#endif
-- * Specs
ImpDeclSpec(..),
ImportSpec(..),
Expand Down Expand Up @@ -425,7 +422,6 @@ import GHC.Core.DataCon hiding (dataConExTyCoVars)
import qualified GHC.Core.DataCon as DataCon
import GHC.Core.FamInstEnv hiding (pprFamInst)
import GHC.Core.InstEnv
import GHC.Types.Unique.FM
import GHC.Core.PatSyn
import GHC.Core.Predicate
import GHC.Core.TyCo.Ppr
Expand Down Expand Up @@ -480,6 +476,7 @@ import GHC.Types.SrcLoc (BufPos, BufSpan,
SrcLoc (UnhelpfulLoc),
SrcSpan (UnhelpfulSpan))
import qualified GHC.Types.SrcLoc as SrcLoc
import GHC.Types.Unique.FM
import GHC.Types.Unique.Supply
import GHC.Types.Var (Var (varName), setTyVarUnique,
setVarUnique)
Expand Down Expand Up @@ -543,23 +540,27 @@ import qualified GHC.Unit.Finder as GHC
#endif

#if MIN_VERSION_ghc(9,3,0)
import GHC.Utils.Error (mkPlainErrorMsgEnvelope)
import GHC.Driver.Env as GHCi
import GHC.Driver.Env.KnotVars
import GHC.Unit.Module.Graph
import GHC.Driver.Errors.Types
import GHC.Types.Unique.Map
import GHC.Types.Unique
import GHC.Utils.TmpFs
import GHC.Utils.Panic
import GHC.Unit.Finder.Types
import GHC.Types.Unique.Map
import GHC.Unit.Env
import GHC.Unit.Module.Graph
import GHC.Unit.Finder.Types
import GHC.Utils.Error (mkPlainErrorMsgEnvelope)
import GHC.Utils.Panic
import GHC.Utils.TmpFs
import qualified GHC.Driver.Config.Tidy as GHC
import qualified GHC.Data.Strict as Strict
import GHC.Driver.Env as GHCi
import qualified GHC.Unit.Finder as GHC
import qualified GHC.Driver.Config.Finder as GHC
#endif

#if MIN_VERSION_ghc(9,5,0)
import GHC.Core (CoreProgram)
#endif

mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO Module.ModLocation
#if MIN_VERSION_ghc(9,3,0)
mkHomeModLocation df mn f = pure $ GHC.mkHomeModLocation (GHC.initFinderOpts df) mn f
Expand Down Expand Up @@ -627,6 +628,7 @@ pattern ExposePackage s a mr <- DynFlags.ExposePackage s a _ mr
pattern ExposePackage s a mr = DynFlags.ExposePackage s a mr
#endif

isVisibleFunArg :: Development.IDE.GHC.Compat.Core.FunTyFlag -> Bool
#if __GLASGOW_HASKELL__ >= 906
isVisibleFunArg = TypesVar.isVisibleFunArg
type FunTyFlag = TypesVar.FunTyFlag
Expand Down Expand Up @@ -729,12 +731,16 @@ makeSimpleDetails hsc_env =
hsc_env
#endif

mkIfaceTc hsc_env sf details _ms tcGblEnv = -- ms is only used in GHC >= 9.4
GHC.mkIfaceTc hsc_env sf details
#if MIN_VERSION_ghc(9,3,0)
_ms
#if MIN_VERSION_ghc(9,5,0)
mkIfaceTc :: HscEnv -> GHC.SafeHaskellMode -> ModDetails -> ModSummary -> Maybe CoreProgram -> TcGblEnv -> IO ModIface
mkIfaceTc = GHC.mkIfaceTc
#elif MIN_VERSION_ghc(9,3,0)
mkIfaceTc :: HscEnv -> GHC.SafeHaskellMode -> ModDetails -> ModSummary -> TcGblEnv -> IO ModIface
mkIfaceTc = GHC.mkIfaceTc
#else
mkIfaceTc :: HscEnv -> GHC.SafeHaskellMode -> ModDetails -> ModSummary -> TcGblEnv -> IO ModIface
mkIfaceTc hsc_env sf details _ms{-::ModSummary is only used in GHC >= 9.4 -} = GHC.mkIfaceTc hsc_env sf details
#endif
tcGblEnv

mkBootModDetailsTc :: HscEnv -> TcGblEnv -> IO ModDetails
mkBootModDetailsTc session = GHC.mkBootModDetailsTc
Expand All @@ -756,11 +762,12 @@ initTidyOpts =
pure
#endif

driverNoStop =
#if MIN_VERSION_ghc(9,3,0)
NoStop
driverNoStop :: StopPhase
driverNoStop = NoStop
#else
StopLn
driverNoStop :: Phase
driverNoStop = StopLn
#endif

#if !MIN_VERSION_ghc(9,3,0)
Expand All @@ -779,15 +786,14 @@ pattern NamedFieldPuns :: Extension
pattern NamedFieldPuns = RecordPuns
#endif

groupOrigin :: MatchGroup GhcRn body -> Origin
#if MIN_VERSION_ghc(9,5,0)
mkVisFunTys = mkScaledFunctionTys
mapLoc :: (a -> b) -> SrcLoc.GenLocated l a -> SrcLoc.GenLocated l b
mapLoc = fmap
groupOrigin = mg_ext
#else
mapLoc :: (a -> b) -> SrcLoc.GenLocated l a -> SrcLoc.GenLocated l b
mapLoc = SrcLoc.mapLoc
groupOrigin :: MatchGroup p body -> Origin
groupOrigin = mg_origin
#endif

Expand Down
9 changes: 5 additions & 4 deletions ghcide/src/Development/IDE/GHC/Compat/Outputable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Development.IDE.GHC.Compat.Outputable (
printSDocQualifiedUnsafe,
printWithoutUniques,
mkPrintUnqualifiedDefault,
PrintUnqualified(..),
PrintUnqualified,
defaultUserStyle,
withPprStyle,
-- * Parser errors
Expand Down Expand Up @@ -60,9 +60,6 @@ import GHC.Driver.Env
import GHC.Driver.Ppr
import GHC.Driver.Session
import qualified GHC.Types.Error as Error
#if MIN_VERSION_ghc(9,7,0)
import GHC.Types.Error (defaultDiagnosticOpts)
#endif
import GHC.Types.Name.Ppr
import GHC.Types.Name.Reader
import GHC.Types.SourceError
Expand All @@ -87,6 +84,10 @@ import GHC.Parser.Errors.Types
import GHC.Driver.Errors.Types (DriverMessage, GhcMessage)
#endif

#if MIN_VERSION_ghc(9,7,0)
import GHC.Types.Error (defaultDiagnosticOpts)
#endif

#if MIN_VERSION_ghc(9,5,0)
type PrintUnqualified = NamePprCtx
#endif
Expand Down
9 changes: 4 additions & 5 deletions ghcide/src/Development/IDE/GHC/Compat/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ import qualified GHC.Parser.Lexer as Lexer
type PsMessages = (Bag WarnMsg, Bag ErrMsg)
#endif

getPsMessages :: PState -> DynFlags -> PsMessages
getPsMessages pst _dflags = --dfags is only used if GHC < 9.2
Copy link
Collaborator Author

@jhrcek jhrcek May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting simplification #2: few more unused DynFlags arguments removed because supported GHCs don't need them anymore.

getPsMessages :: PState -> PsMessages
getPsMessages pst =
#if MIN_VERSION_ghc(9,3,0)
uncurry PsMessages $ Lexer.getPsMessages pst
#else
bimap (fmap pprWarning) (fmap pprError) $
getMessages pst
#endif

applyPluginsParsedResultAction :: HscEnv -> DynFlags -> ModSummary -> Parser.ApiAnns -> ParsedSource -> PsMessages -> IO (ParsedSource, PsMessages)
applyPluginsParsedResultAction env _dflags ms hpm_annotations parsed msgs = do
-- dflags is only used in GHC < 9.2
applyPluginsParsedResultAction :: HscEnv -> ModSummary -> Parser.ApiAnns -> ParsedSource -> PsMessages -> IO (ParsedSource, PsMessages)
applyPluginsParsedResultAction env ms hpm_annotations parsed msgs = do
-- Apply parsedResultAction of plugins
let applyPluginAction p opts = parsedResultAction p opts ms
#if MIN_VERSION_ghc(9,3,0)
Expand Down
Loading