Skip to content

Cleanup imports after CPP removal + few hlint fixes #4337

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 3 commits into from
Jun 27, 2024
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
14 changes: 5 additions & 9 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@
import Data.HashMap.Strict (HashMap)
import Data.HashSet (HashSet)
import qualified Data.HashSet as Set
import qualified Data.Set as OS
import Database.SQLite.Simple
import Development.IDE.Core.Tracing (withTrace)
import Development.IDE.Core.WorkerThread (awaitRunInThread,
withWorkerQueue)
import qualified Development.IDE.GHC.Compat.Util as Compat
import Development.IDE.Session.Diagnostics (renderCradleError)
import Development.IDE.Types.Shake (WithHieDb,
WithHieDbShield (..),
toNoFileKey)
import GHC.Data.Graph.Directed
import HieDb.Create
import HieDb.Types
import HieDb.Utils
Expand All @@ -116,13 +119,6 @@
import System.Random (RandomGen)
import Text.ParserCombinators.ReadP (readP_to_S)


-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removing 9.2 compat code removed a lot of import CPP, making many of these comments irrelevant.


import qualified Data.Set as OS
import qualified Development.IDE.GHC.Compat.Util as Compat
import GHC.Data.Graph.Directed

import GHC.Data.Bag
import GHC.Driver.Env (hsc_all_home_unit_ids)
import GHC.Driver.Errors.Types
Expand Down Expand Up @@ -642,7 +638,7 @@
[] -> error $ "GHC version could not be parsed: " <> version
((runTime, _):_)
| compileTime == runTime -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))

Check warning on line 641 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef' cradle_files (\\ xs -> (cfp : xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ cradle_files ((:) cfp)"
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
| otherwise -> return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
-- Failure case, either a cradle error or the none cradle
Expand Down Expand Up @@ -832,7 +828,7 @@
where
go rest this this_uis =
plusUniqMap_C OS.union
(addToUniqMap_C OS.union external_depends this (OS.fromList $ this_deps))
(addToUniqMap_C OS.union external_depends this (OS.fromList this_deps))
rest
where
external_depends = mapUniqMap (OS.fromList . unitDepends)
Expand Down Expand Up @@ -890,7 +886,7 @@
x <- bagToList $ mapBag errMsgDiagnostic $ unionManyBags $ map Compat.getMessages closure_errs
DriverHomePackagesNotClosed us <- pure x
pure us
isBad ci = (homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units

Check warning on line 889 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in newComponentCache in module Development.IDE.Session: Redundant bracket ▫︎ Found: "(homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units" ▫︎ Perhaps: "homeUnitId_ (componentDynFlags ci) `OS.member` bad_units"
-- Whenever we spin up a session on Linux, dynamically load libm.so.6
-- in. We need this in case the binary is statically linked, in which
-- case the interactive session will fail when trying to load
Expand Down Expand Up @@ -1154,7 +1150,7 @@
-- This works because there won't be any dependencies on the
-- executable unit.
"main" ->
let hash = B.unpack $ B16.encode $ H.finalize $ H.updates H.init (map B.pack $ this_opts)
let hash = B.unpack $ B16.encode $ H.finalize $ H.updates H.init (map B.pack this_opts)
hashed_uid = Compat.toUnitId (Compat.stringToUnit ("main-"++hash))
in setHomeUnitId_ hashed_uid dflags'
_ -> dflags'
Expand Down
91 changes: 48 additions & 43 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,71 +39,78 @@
) where

import Control.Concurrent.Extra
import Control.Concurrent.STM.Stats hiding (orElse)
import Control.DeepSeq (NFData (..), force, rnf)
import Control.Exception (evaluate)
import Control.Concurrent.STM.Stats hiding (orElse)
import Control.DeepSeq (NFData (..), force,
rnf)
import Control.Exception (evaluate)
import Control.Exception.Safe
import Control.Lens hiding (List, pre, (<.>))
import Control.Lens hiding (List, pre,
(<.>))
import Control.Monad.Extra
import Control.Monad.IO.Class
import Control.Monad.Trans.Except
import qualified Control.Monad.Trans.State.Strict as S
import Data.Aeson (toJSON)
import Data.Bifunctor (first, second)
import qualified Control.Monad.Trans.State.Strict as S
import Data.Aeson (toJSON)
import Data.Bifunctor (first, second)
import Data.Binary
import qualified Data.ByteString as BS
import qualified Data.ByteString as BS
import Data.Coerce
import qualified Data.DList as DL
import qualified Data.DList as DL
import Data.Functor
import Data.Generics.Aliases
import Data.Generics.Schemes
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import qualified Data.HashMap.Strict as HashMap
import Data.IntMap (IntMap)
import Data.IORef
import Data.List.Extra
import qualified Data.Map.Strict as Map
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Proxy (Proxy (Proxy))
import qualified Data.Text as T
import Data.Time (UTCTime (..))
import Data.Tuple.Extra (dupe)
import Data.Proxy (Proxy (Proxy))
import qualified Data.Text as T
import Data.Time (UTCTime (..))
import Data.Tuple.Extra (dupe)
import Debug.Trace
import Development.IDE.Core.FileStore (resetInterfaceStore)
import Development.IDE.Core.FileStore (resetInterfaceStore)

Check warning on line 73 in ghcide/src/Development/IDE/Core/Compile.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Development.IDE.Core.Compile: Use fewer imports ▫︎ Found: "import Development.IDE.Core.FileStore ( resetInterfaceStore )\nimport Development.IDE.Core.FileStore ( shareFilePath )\n" ▫︎ Perhaps: "import Development.IDE.Core.FileStore\n ( resetInterfaceStore, shareFilePath )\n"
import Development.IDE.Core.Preprocessor
import Development.IDE.Core.ProgressReporting (ProgressReporting (..),
progressReportingOutsideState)
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake
import Development.IDE.Core.Tracing (withTrace)
import Development.IDE.GHC.Compat hiding (assert,
loadInterface, parseHeader,
parseModule, tcRnModule,
writeHieFile)
import qualified Development.IDE.GHC.Compat as Compat
import qualified Development.IDE.GHC.Compat as GHC
import qualified Development.IDE.GHC.Compat.Util as Util
import Development.IDE.Core.ProgressReporting (ProgressReporting (..), progressReportingOutsideState)
import Development.IDE.Core.Tracing (withTrace)
import Development.IDE.GHC.Compat hiding (assert,
loadInterface,
parseHeader,
parseModule,
tcRnModule,
writeHieFile)
import qualified Development.IDE.GHC.Compat as Compat
import qualified Development.IDE.GHC.Compat as GHC
import qualified Development.IDE.GHC.Compat.Util as Util
import Development.IDE.GHC.CoreFile
import Development.IDE.GHC.Error
import Development.IDE.GHC.Orphans ()
import Development.IDE.GHC.Orphans ()
import Development.IDE.GHC.Util
import Development.IDE.GHC.Warnings
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Location
import Development.IDE.Types.Options
import GHC (ForeignHValue,
GetDocsFailure (..),
parsedSource)
import qualified GHC.LanguageExtensions as LangExt
import GHC (ForeignHValue,
GetDocsFailure (..),
parsedSource)
import qualified GHC.LanguageExtensions as LangExt
import GHC.Serialized
import HieDb hiding (withHieDb)
import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types (DiagnosticTag (..))
import qualified Language.LSP.Server as LSP
import Prelude hiding (mod)
import HieDb hiding (withHieDb)
import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types (DiagnosticTag (..))
import qualified Language.LSP.Server as LSP
import Prelude hiding (mod)
import System.Directory
import System.FilePath
import System.IO.Extra (fixIO, newTempFileWithin)
import System.IO.Extra (fixIO,
newTempFileWithin)

import qualified GHC as G
import qualified Data.Set as Set
import qualified GHC as G
import GHC.Tc.Gen.Splice
import GHC.Types.ForeignStubs
import GHC.Types.HpcInfo
Expand All @@ -112,18 +119,16 @@
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import qualified Data.Set as Set

#if MIN_VERSION_ghc(9,5,0)
import GHC.Core.Lint.Interactive
import GHC.Driver.Config.CoreToStg.Prep
#endif

#if MIN_VERSION_ghc(9,7,0)
import Data.Foldable (toList)
import Data.Foldable (toList)
import GHC.Unit.Module.Warnings
#else
import Development.IDE.Core.FileStore (shareFilePath)
import Development.IDE.Core.FileStore (shareFilePath)
#endif

--Simple constants to make sure the source is consistently named
Expand Down Expand Up @@ -292,7 +297,7 @@

{- load it -}
; (fv_hvs, lbss, pkgs) <- loadDecls (hscInterp hsc_env') hsc_env' srcspan bcos
; let hval = ((expectJust "hscCompileCoreExpr'" $ lookup (idName binding_id) fv_hvs), lbss, pkgs)
; let hval = (expectJust "hscCompileCoreExpr'" $ lookup (idName binding_id) fv_hvs, lbss, pkgs)

; modifyIORef' var (flip extendModuleEnvList [(mi_module $ hm_iface hm, linkableHash lb) | lb <- lbs, let hm = linkableHomeMod lb])
; return hval }
Expand Down Expand Up @@ -953,7 +958,7 @@


convImport (L _ i) = (
(ideclPkgQual i)

Check warning on line 961 in ghcide/src/Development/IDE/Core/Compile.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in getModSummaryFromImports in module Development.IDE.Core.Compile: Redundant bracket ▫︎ Found: "((ideclPkgQual i), reLoc $ ideclName i)" ▫︎ Perhaps: "(ideclPkgQual i, reLoc $ ideclName i)"
, reLoc $ ideclName i)

msrImports = implicit_imports ++ imps
Expand Down
5 changes: 1 addition & 4 deletions ghcide/src/Development/IDE/Core/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ import Development.IDE.GHC.Error
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Location
import qualified GHC.LanguageExtensions as LangExt
import GHC.Utils.Logger (LogFlags (..))
import System.FilePath
import System.IO.Extra

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

import GHC.Utils.Logger (LogFlags (..))

-- | Given a file and some contents, apply any necessary preprocessors,
-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
preprocessor :: HscEnv -> FilePath -> Maybe Util.StringBuffer -> ExceptT [FileDiagnostic] IO (Util.StringBuffer, [String], HscEnv, Util.Fingerprint)
Expand Down
7 changes: 1 addition & 6 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,8 @@
import System.Info.Extra (isWindows)


import GHC.Fingerprint

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import qualified Data.IntMap as IM

import GHC.Fingerprint


data Log
Expand Down Expand Up @@ -794,7 +789,7 @@
{ source_version = ver
, old_value = m_old
, get_file_version = use GetModificationTime_{missingFileDiagnostics = False}
, get_linkable_hashes = \fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs

Check warning on line 792 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in getModIfaceFromDiskRule in module Development.IDE.Core.Rules: Use fmap ▫︎ Found: "\\ fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs" ▫︎ Perhaps: "fmap (map (snd . fromJust . hirCoreFp)) . uses_ GetModIface"
, regenerate = regenerateHiFile session f ms
}
r <- loadInterface (hscEnv session) ms linkableType recompInfo
Expand Down Expand Up @@ -1068,7 +1063,7 @@
-- thus bump its modification time, forcing this rule to be rerun every time.
exists <- liftIO $ doesFileExist obj_file
mobj_time <- liftIO $
if exists

Check warning on line 1066 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in getLinkableRule in module Development.IDE.Core.Rules: Use whenMaybe ▫︎ Found: "if exists then Just <$> getModTime obj_file else pure Nothing" ▫︎ Perhaps: "whenMaybe exists (getModTime obj_file)"
then Just <$> getModTime obj_file
else pure Nothing
case mobj_time of
Expand Down
5 changes: 1 addition & 4 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Tracing
import Development.IDE.Core.WorkerThread
import Development.IDE.GHC.Compat (NameCache,
NameCacheUpdater,
initNameCache,
knownKeyNames)
import Development.IDE.GHC.Orphans ()
Expand Down Expand Up @@ -174,10 +175,6 @@ import System.FilePath hiding (makeRelative)
import System.IO.Unsafe (unsafePerformIO)
import System.Time.Extra

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import Development.IDE.GHC.Compat (NameCacheUpdater)

data Log
= LogCreateHieDbExportsMapStart
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Tracing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ withTelemetryRecorder k = withSpan "Logger" $ \sp ->
-- | Returns a logger that produces telemetry events in a single span.
telemetryLogRecorder :: SpanInFlight -> Recorder (WithPriority (Doc a))
telemetryLogRecorder sp = Recorder $ \WithPriority {..} ->
liftIO $ addEvent sp (fromString $ show priority) (encodeUtf8 $ trim $ renderStrict $ layoutCompact $ payload)
liftIO $ addEvent sp (fromString $ show priority) (encodeUtf8 $ trim $ renderStrict $ layoutCompact payload)
where
-- eventlog message size is limited by EVENT_PAYLOAD_SIZE_MAX = STG_WORD16_MAX
trim = T.take (fromIntegral(maxBound :: Word16) - 10)
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/GHC/CPP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import GHC.Settings

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


#if !MIN_VERSION_ghc(9,5,0)
import qualified GHC.Driver.Pipeline.Execute as Pipeline
#endif
Expand Down
8 changes: 3 additions & 5 deletions ghcide/src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import GHC.Builtin.Uniques
import GHC.ByteCode.Types
import GHC.CoreToStg
import GHC.Data.Maybe
import GHC.Driver.Config.Stg.Pipeline
import GHC.Driver.Env as Env
import GHC.Iface.Env
import GHC.Linker.Loader (loadDecls, loadExpr)
Expand All @@ -181,15 +182,12 @@ import GHC.Types.IPE
import GHC.Types.SrcLoc (combineRealSrcSpans)
import GHC.Unit.Home.ModInfo (HomePackageTable,
lookupHpt)
import GHC.Unit.Module.Deps (Dependencies (dep_direct_mods),
Usage (..))
import GHC.Unit.Module.ModIface

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import GHC.Driver.Config.Stg.Pipeline
import GHC.Unit.Module.Deps (Dependencies (dep_direct_mods),
Usage (..))

#if !MIN_VERSION_ghc(9,5,0)
import GHC.Core.Lint (lintInteractiveExpr)
#endif
Expand Down
42 changes: 21 additions & 21 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
moduleUnit, toUnitId)
import qualified GHC.Unit.Module as Module
import GHC.Unit.State (ModuleOrigin (..))
import GHC.Utils.Error (Severity (..), emptyMessages)

Check warning on line 482 in ghcide/src/Development/IDE/GHC/Compat/Core.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Development.IDE.GHC.Compat.Core: Use fewer imports ▫︎ Found: "import GHC.Utils.Error ( Severity(..), emptyMessages )\nimport GHC.Utils.Error ( mkPlainErrorMsgEnvelope )\n" ▫︎ Perhaps: "import GHC.Utils.Error\n ( Severity(..), emptyMessages, mkPlainErrorMsgEnvelope )\n"
import GHC.Utils.Panic hiding (try)
import qualified GHC.Utils.Panic.Plain as Plain

Expand All @@ -487,12 +487,15 @@
import Data.Foldable (toList)
import GHC.Core.Multiplicity (scaledThing)
import GHC.Data.Bag
import qualified GHC.Data.Strict as Strict
import qualified GHC.Driver.Config.Finder as GHC
import qualified GHC.Driver.Config.Tidy as GHC
import GHC.Driver.Env
import GHC.Hs (HsModule (..))
#if !MIN_VERSION_ghc(9,9,0)
import GHC.Hs (SrcSpanAnn')
#endif
import GHC.Hs.Decls hiding (FunDep)
import GHC.Driver.Env as GHCi
import GHC.Driver.Env.KnotVars
import GHC.Driver.Errors.Types
import GHC.Hs (HsModule (..))
import GHC.Hs.Decls hiding (FunDep)
import GHC.Hs.Doc
import GHC.Hs.Expr
import GHC.Hs.Extension
Expand All @@ -516,39 +519,36 @@
import GHC.Types.Target (Target (..), TargetId (..))
import GHC.Types.TyThing
import GHC.Types.TyThing.Ppr
import GHC.Types.Unique
import GHC.Types.Unique.Map
import GHC.Unit.Env
import GHC.Unit.Finder hiding (mkHomeModLocation)
import qualified GHC.Unit.Finder as GHC
import GHC.Unit.Finder.Types
import GHC.Unit.Home.ModInfo
import GHC.Unit.Module.Graph
import GHC.Unit.Module.Imported
import GHC.Unit.Module.ModDetails
import GHC.Unit.Module.ModGuts
import GHC.Unit.Module.ModIface (IfaceExport, ModIface,
ModIface_ (..), mi_fix)
import GHC.Unit.Module.ModSummary (ModSummary (..))
import GHC.Utils.Error (mkPlainErrorMsgEnvelope)
import GHC.Utils.Panic
import GHC.Utils.TmpFs
import Language.Haskell.Syntax hiding (FunDep)

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import qualified GHC.Data.Strict as Strict
import qualified GHC.Driver.Config.Finder as GHC
import qualified GHC.Driver.Config.Tidy as GHC
import GHC.Driver.Env as GHCi
import GHC.Driver.Env.KnotVars
import GHC.Driver.Errors.Types
import GHC.Types.Unique
import GHC.Types.Unique.Map
import GHC.Unit.Env
import qualified GHC.Unit.Finder as GHC
import GHC.Unit.Finder.Types
import GHC.Unit.Module.Graph
import GHC.Utils.Error (mkPlainErrorMsgEnvelope)
import GHC.Utils.Panic
import GHC.Utils.TmpFs

#if !MIN_VERSION_ghc(9,7,0)
import GHC.Types.Avail (greNamePrintableName)
#endif

#if !MIN_VERSION_ghc(9,9,0)
import GHC.Hs (SrcSpanAnn')
#endif

mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO Module.ModLocation
mkHomeModLocation df mn f = pure $ GHC.mkHomeModLocation (GHC.initFinderOpts df) mn f

Expand Down
7 changes: 1 addition & 6 deletions ghcide/src/Development/IDE/GHC/Compat/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Development.IDE.GHC.Compat.Env (
import GHC (setInteractiveDynFlags)

import GHC.Driver.Backend as Backend
import GHC.Driver.Env (HscEnv, hscSetActiveUnitId)
import qualified GHC.Driver.Env as Env
import GHC.Driver.Hooks (Hooks)
import GHC.Driver.Session
Expand All @@ -69,12 +70,6 @@ import GHC.Unit.Types (UnitId)
import GHC.Utils.Logger
import GHC.Utils.TmpFs

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]


import GHC.Driver.Env (HscEnv, hscSetActiveUnitId)



hsc_EPS :: HscEnv -> UnitEnv
hsc_EPS = Env.hsc_unit_env
Expand Down
3 changes: 1 addition & 2 deletions ghcide/src/Development/IDE/GHC/Compat/Iface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ module Development.IDE.GHC.Compat.Iface (
import Development.IDE.GHC.Compat.Env
import Development.IDE.GHC.Compat.Outputable
import GHC
import GHC.Driver.Session (targetProfile)
import qualified GHC.Iface.Load as Iface
import GHC.Unit.Finder.Types (FindResult)

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

import GHC.Driver.Session (targetProfile)

#if MIN_VERSION_ghc(9,7,0)
import GHC.Iface.Errors.Ppr (missingInterfaceErrorDiagnostic)
import GHC.Iface.Errors.Types (IfaceMessage)
Expand Down
Loading
Loading