Skip to content

Commit

Permalink
fix unused-top-binds unused-local-binds orphans unused-matches and un…
Browse files Browse the repository at this point in the history
…ticked-promoted-constructors
  • Loading branch information
joyfulmantis committed Aug 17, 2023
1 parent 4bee82e commit ccd80e8
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 59 deletions.
7 changes: 1 addition & 6 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,11 @@ library
-Wwarn=missing-signatures
-Wwarn=duplicate-exports
-Wwarn=dodgy-exports
-Wwarn=unused-top-binds
-Wwarn=incomplete-patterns
-Wwarn=unused-local-binds
-Wwarn=orphans
-Wwarn=unused-matches
-Wwarn=overlapping-patterns
-Wwarn=incomplete-record-updates
-Wwarn=unticked-promoted-constructors

if impl(ghc >= 9) && flag(pedantic)
if impl(ghc >= 9.2) && flag(pedantic)
ghc-options: -Wwarn=ambiguous-fields

if impl(ghc >= 9)
Expand Down
6 changes: 3 additions & 3 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
#if MIN_VERSION_ghc(9,3,0)
let (df2, uids) = (rawComponentDynFlags, [])
#else
let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags
let (df2, uids) = _removeInplacePackages fakeUid inplace rawComponentDynFlags
#endif
let prefix = show rawComponentUnitId
-- See Note [Avoiding bad interface files]
Expand Down Expand Up @@ -1070,12 +1070,12 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs
-- There are several places in GHC (for example the call to hptInstances in
-- tcRnImports) which assume that all modules in the HPT have the same unit
-- ID. Therefore we create a fake one and give them all the same unit id.
removeInplacePackages
_removeInplacePackages
:: UnitId -- ^ fake uid to use for our internal component
-> [UnitId]
-> DynFlags
-> (DynFlags, [UnitId])
removeInplacePackages fake_uid us df = (setHomeUnitId_ fake_uid $
_removeInplacePackages fake_uid us df = (setHomeUnitId_ fake_uid $
df { packageFlags = ps }, uids)
where
(uids, ps) = Compat.filterInplaceUnits us (packageFlags df)
Expand Down
30 changes: 15 additions & 15 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ generateHieAsts hscEnv tcm =
where
dflags = hsc_dflags hscEnv
#if MIN_VERSION_ghc(9,0,0)
run ts =
run _ts =
#if MIN_VERSION_ghc(9,2,0) && !MIN_VERSION_ghc(9,3,0)
fmap (join . snd) . liftIO . initDs hscEnv ts
fmap (join . snd) . liftIO . initDs hscEnv _ts
#else
id
#endif
Expand Down Expand Up @@ -1086,7 +1086,7 @@ mergeEnvs env mg ms extraMods envs = do
-- Prefer non-boot files over non-boot files
-- otherwise we can get errors like https://gitlab.haskell.org/ghc/ghc/-/issues/19816
-- if a boot file shadows over a non-boot file
combineModuleLocations a@(InstalledFound ml m) b | Just fp <- ml_hs_file ml, not ("boot" `isSuffixOf` fp) = a
combineModuleLocations a@(InstalledFound ml _) _ | Just fp <- ml_hs_file ml, not ("boot" `isSuffixOf` fp) = a
combineModuleLocations _ b = b

concatFC :: FinderCacheState -> [FinderCache] -> IO FinderCache
Expand Down Expand Up @@ -1135,9 +1135,9 @@ getModSummaryFromImports
-> UTCTime
-> Maybe Util.StringBuffer
-> ExceptT [FileDiagnostic] IO ModSummaryResult
getModSummaryFromImports env fp modTime mContents = do
getModSummaryFromImports env fp _modTime mContents = do

(contents, opts, ppEnv, src_hash) <- preprocessor env fp mContents
(contents, opts, ppEnv, _src_hash) <- preprocessor env fp mContents

let dflags = hsc_dflags ppEnv

Expand All @@ -1153,7 +1153,7 @@ getModSummaryFromImports env fp modTime mContents = do
(src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource.unLoc) imps

-- GHC.Prim doesn't exist physically, so don't go looking for it.
(ordinary_imps, ghc_prim_imports)
(ordinary_imps, _ghc_prim_imports)
= partition ((/= moduleName gHC_PRIM) . unLoc
. ideclName . unLoc)
ord_idecls
Expand All @@ -1177,7 +1177,7 @@ getModSummaryFromImports env fp modTime mContents = do
rn_imps = fmap (\(pk, lmn@(L _ mn)) -> (rn_pkg_qual mn pk, lmn))
srcImports = rn_imps $ map convImport src_idecls
textualImports = rn_imps $ map convImport (implicit_imports ++ ordinary_imps)
ghc_prim_import = not (null ghc_prim_imports)
ghc_prim_import = not (null _ghc_prim_imports)
#else
srcImports = map convImport src_idecls
textualImports = map convImport (implicit_imports ++ ordinary_imps)
Expand All @@ -1204,10 +1204,10 @@ getModSummaryFromImports env fp modTime mContents = do
#if MIN_VERSION_ghc(9,3,0)
, ms_dyn_obj_date = Nothing
, ms_ghc_prim_import = ghc_prim_import
, ms_hs_hash = src_hash
, ms_hs_hash = _src_hash

#else
, ms_hs_date = modTime
, ms_hs_date = _modTime
#endif
, ms_hsc_src = sourceType
-- The contents are used by the GetModSummary rule
Expand Down Expand Up @@ -1475,19 +1475,19 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do

-- The source is modified if it is newer than the destination (iface file)
-- A more precise check for the core file is performed later
let sourceMod = case mb_dest_version of
let _sourceMod = case mb_dest_version of
Nothing -> SourceModified -- destination file doesn't exist, assume modified source
Just dest_version
| source_version <= dest_version -> SourceUnmodified
| otherwise -> SourceModified

old_iface <- case mb_old_iface of
_old_iface <- case mb_old_iface of
Just iface -> pure (Just iface)
Nothing -> do
let ncu = hsc_NC sessionWithMsDynFlags
read_dflags = hsc_dflags sessionWithMsDynFlags
let _ncu = hsc_NC sessionWithMsDynFlags
_read_dflags = hsc_dflags sessionWithMsDynFlags
#if MIN_VERSION_ghc(9,3,0)
read_result <- liftIO $ readIface read_dflags ncu mod iface_file
read_result <- liftIO $ readIface _read_dflags _ncu mod iface_file
#else
read_result <- liftIO $ initIfaceCheck (text "readIface") sessionWithMsDynFlags
$ readIface mod iface_file
Expand All @@ -1502,7 +1502,7 @@ loadInterface session ms linkableNeeded RecompilationInfo{..} = do
-- given that the source is unmodified
(recomp_iface_reqd, mb_checked_iface)
#if MIN_VERSION_ghc(9,3,0)
<- liftIO $ checkOldIface sessionWithMsDynFlags ms old_iface >>= \case
<- liftIO $ checkOldIface sessionWithMsDynFlags ms _old_iface >>= \case
UpToDateItem x -> pure (UpToDate, Just x)
OutOfDateItem reason x -> pure (NeedsRecompile reason, x)
#else
Expand Down
7 changes: 2 additions & 5 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,6 @@ getModIfaceFromDiskRule recorder = defineEarlyCutoff (cmapWithPrio LogShake reco
Just session -> do
linkableType <- getLinkableType f
ver <- use_ GetModificationTime f
ShakeExtras{ideNc} <- getShakeExtras
let m_old = case old of
Shake.Succeeded (Just old_version) v -> Just (v, old_version)
Shake.Stale _ (Just old_version) v -> Just (v, old_version)
Expand Down Expand Up @@ -1126,8 +1125,6 @@ getLinkableRule recorder =
Nothing -> error "called GetLinkable for a file without a linkable"
Just (bin_core, fileHash) -> do
session <- use_ GhcSessionDeps f
ShakeExtras{ideNc} <- getShakeExtras
let namecache_updater = mkUpdater ideNc
linkableType <- getLinkableType f >>= \case
Nothing -> error "called GetLinkable for a file which doesn't need compilation"
Just t -> pure t
Expand Down Expand Up @@ -1222,11 +1219,11 @@ computeLinkableTypeForDynFlags d
#if defined(GHC_PATCHED_UNBOXED_BYTECODE) || MIN_VERSION_ghc(9,2,0)
= BCOLinkable
#else
| unboxed_tuples_or_sums = ObjectLinkable
| _unboxed_tuples_or_sums = ObjectLinkable
| otherwise = BCOLinkable
#endif
where
unboxed_tuples_or_sums =
_unboxed_tuples_or_sums =
xopt LangExt.UnboxedTuples d || xopt LangExt.UnboxedSums d

-- | Tracks which linkables are current, so we don't need to unload them
Expand Down
3 changes: 0 additions & 3 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -994,9 +994,6 @@ usesWithStale_ key files = do
newtype IdeAction a = IdeAction { runIdeActionT :: (ReaderT ShakeExtras IO) a }
deriving newtype (MonadReader ShakeExtras, MonadIO, Functor, Applicative, Monad, Semigroup)

-- https://hub.darcs.net/ross/transformers/issue/86
deriving instance (Semigroup (m a)) => Semigroup (ReaderT r m a)

runIdeAction :: String -> ShakeExtras -> IdeAction a -> IO a
runIdeAction _herald s i = runReaderT (runIdeActionT i) s

Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/Core/UseStale.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ dualPositionMap (PositionMap (P.PositionMapping (P.PositionDelta from to))) =
-- a 'PositionMapping' that will fast-forward values to the current age.
data TrackedStale a where
TrackedStale
:: Tracked (Stale s) a
-> PositionMap (Stale s) Current
:: Tracked ('Stale s) a
-> PositionMap ('Stale s) 'Current
-> TrackedStale a

instance Functor TrackedStale where
Expand Down Expand Up @@ -136,7 +136,7 @@ unsafeMkCurrent :: age -> Tracked 'Current age
unsafeMkCurrent = coerce


unsafeMkStale :: age -> Tracked (Stale s) age
unsafeMkStale :: age -> Tracked ('Stale s) age
unsafeMkStale = coerce


Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,10 @@ makeSimpleDetails hsc_env =
hsc_env
#endif

mkIfaceTc hsc_env sf details ms tcGblEnv =
mkIfaceTc hsc_env sf details _ms tcGblEnv =
GHC.mkIfaceTc hsc_env sf details
#if MIN_VERSION_ghc(9,3,0)
ms
_ms
#endif
tcGblEnv

Expand Down
5 changes: 5 additions & 0 deletions ghcide/src/Development/IDE/GHC/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Development.IDE.GHC.Compat
import Development.IDE.GHC.Util

import Control.DeepSeq
import Control.Monad.Trans.Reader (ReaderT (..))
import Data.Aeson
import Data.Hashable
import Data.String (IsString (fromString))
Expand Down Expand Up @@ -52,6 +53,10 @@ import GHC.Types.PkgQual
import GHC.Unit.Home.ModInfo
#endif

-- Orphan instance for Shake.hs
-- https://hub.darcs.net/ross/transformers/issue/86
deriving instance (Semigroup (m a)) => Semigroup (ReaderT r m a)

-- Orphan instances for types from the GHC API.
instance Show CoreModule where show = unpack . printOutputable
instance NFData CoreModule where rnf = rwhnf
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Import/FindImports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do
hpt_deps :: [UnitId]
hpt_deps = homeUnitDepends units
#else
import_paths'
_import_paths'
#endif

-- first try to find the module as a file. If we can't find it try to find it in the package
-- database.
-- Here the importPaths for the current modules are added to the front of the import paths from the other components.
-- This is particularly important for Paths_* modules which get generated for every component but unless you use it in
-- each component will end up being found in the wrong place and cause a multi-cradle match failure.
import_paths' =
_import_paths' =
#if MIN_VERSION_ghc(9,3,0)
import_paths
#else
Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ runLanguageServer
-> config
-> (config -> Value -> Either T.Text config)
-> (MVar ()
-> IO (LSP.LanguageContextEnv config -> TRequestMessage Method_Initialize -> IO (Either ResponseError (LSP.LanguageContextEnv config, a)),
-> IO (LSP.LanguageContextEnv config -> TRequestMessage 'Method_Initialize -> IO (Either ResponseError (LSP.LanguageContextEnv config, a)),
LSP.Handlers (m config),
(LanguageContextEnv config, a) -> m config <~> IO))
-> IO ()
Expand Down Expand Up @@ -132,7 +132,7 @@ setupLSP ::
-> LSP.Handlers (ServerM config)
-> (LSP.LanguageContextEnv config -> Maybe FilePath -> WithHieDb -> IndexQueue -> IO IdeState)
-> MVar ()
-> IO (LSP.LanguageContextEnv config -> TRequestMessage Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState)),
-> IO (LSP.LanguageContextEnv config -> TRequestMessage 'Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState)),
LSP.Handlers (ServerM config),
(LanguageContextEnv config, IdeState) -> ServerM config <~> IO)
setupLSP recorder getHieDbLoc userHandlers getIdeState clientMsgVar = do
Expand Down Expand Up @@ -194,7 +194,7 @@ handleInit
-> (SomeLspId -> IO ())
-> (SomeLspId -> IO ())
-> Chan ReactorMessage
-> LSP.LanguageContextEnv config -> TRequestMessage Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState))
-> LSP.LanguageContextEnv config -> TRequestMessage 'Method_Initialize -> IO (Either err (LSP.LanguageContextEnv config, IdeState))
handleInit recorder getHieDbLoc getIdeState lifetime exitClientMsg clearReqId waitForCancel clientMsgChan env (TRequestMessage _ _ m params) = otTracedHandler "Initialize" (show m) $ \sp -> do
traceWithSpan sp params
let root = LSP.resRootPath env
Expand Down
8 changes: 4 additions & 4 deletions ghcide/src/Development/IDE/LSP/Outline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,25 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam
}
cvtFld _ = Nothing
#else
[ (defDocumentSymbol l :: DocumentSymbol)
[ (defDocumentSymbol l'' :: DocumentSymbol)
{ _name = printOutputable n
, _kind = SymbolKind_Constructor
, _selectionRange = realSrcSpanToRange l'
, _children = conArgRecordFields (con_args x)
}
| L (locA -> (RealSrcSpan l _ )) x <- dd_cons
| L (locA -> (RealSrcSpan l'' _ )) x <- dd_cons
, L (locA -> (RealSrcSpan l' _)) n <- getConNames' x
]
}
where
-- | Extract the record fields of a constructor
conArgRecordFields (RecCon (L _ lcdfs)) = Just
[ (defDocumentSymbol l :: DocumentSymbol)
[ (defDocumentSymbol l' :: DocumentSymbol)
{ _name = printOutputable n
, _kind = SymbolKind_Field
}
| L _ cdf <- lcdfs
, L (locA -> (RealSrcSpan l _)) n <- rdrNameFieldOcc . unLoc <$> cd_fld_names cdf
, L (locA -> (RealSrcSpan l' _)) n <- rdrNameFieldOcc . unLoc <$> cd_fld_names cdf
]
conArgRecordFields _ = Nothing
#endif
Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/LSP/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Control.Monad.IO.Unlift (MonadUnliftIO)
import Control.Monad.Reader
import Development.IDE.Core.Shake
import Development.IDE.Core.Tracing
import Ide.Types (HasTracing, traceWithSpan)
import Ide.Types
import Language.LSP.Protocol.Message
import Language.LSP.Server (Handlers, LspM)
import qualified Language.LSP.Server as LSP
Expand All @@ -30,7 +30,7 @@ newtype ServerM c a = ServerM { unServerM :: ReaderT (ReactorChan, IdeState) (Ls
deriving (Functor, Applicative, Monad, MonadReader (ReactorChan, IdeState), MonadIO, MonadUnliftIO, LSP.MonadLsp c)

requestHandler
:: forall (m :: Method ClientToServer Request) c. (HasTracing (MessageParams m)) =>
:: forall m c. PluginMethod 'Request m =>
SMethod m
-> (IdeState -> MessageParams m -> LspM c (Either ResponseError (MessageResult m)))
-> Handlers (ServerM c)
Expand All @@ -45,7 +45,7 @@ requestHandler m k = LSP.requestHandler m $ \TRequestMessage{_method,_id,_params
writeChan chan $ ReactorRequest (SomeLspId _id) (trace $ LSP.runLspT env $ resp' =<< k ide _params) (LSP.runLspT env . resp' . Left)

notificationHandler
:: forall (m :: Method ClientToServer Notification) c. (HasTracing (MessageParams m)) =>
:: forall m c. PluginMethod 'Notification m =>
SMethod m
-> (IdeState -> VFS -> MessageParams m -> LspM c ())
-> Handlers (ServerM c)
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Plugin/HLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ logErrors recorder errs = do


-- | Combine the 'PluginHandler' for all plugins
newtype IdeHandler (m :: Method ClientToServer Request)
newtype IdeHandler (m :: Method 'ClientToServer 'Request)
= IdeHandler [(PluginId, PluginDescriptor IdeState, IdeState -> MessageParams m -> LSP.LspM Config (NonEmpty (Either PluginError (MessageResult m))))]

-- | Combine the 'PluginHandler' for all plugins
newtype IdeNotificationHandler (m :: Method ClientToServer Notification)
newtype IdeNotificationHandler (m :: Method 'ClientToServer 'Notification)
= IdeNotificationHandler [(PluginId, PluginDescriptor IdeState, IdeState -> VFS -> MessageParams m -> LSP.LspM Config ())]
-- type NotificationHandler (m :: Method ClientToServer Notification) = MessageParams m -> IO ()`

Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Plugin/TypeLenses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ properties = emptyProperties
, (Diagnostics, "Follows error messages produced by GHC about missing signatures")
] Always

codeLensProvider :: PluginMethodHandler IdeState Method_TextDocumentCodeLens
codeLensProvider :: PluginMethodHandler IdeState 'Method_TextDocumentCodeLens
codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentifier uri} = do
mode <- liftIO $ runAction "codeLens.config" ideState $ usePropertyAction #mode pId properties
nfp <- getNormalizedFilePathE uri
Expand Down Expand Up @@ -162,7 +162,7 @@ codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentif
let allDiags = diags <> hDiags
pure $ InL $ generateLensFromGlobalDiags allDiags

codeLensResolveProvider :: ResolveFunction IdeState TypeLensesResolve Method_CodeLensResolve
codeLensResolveProvider :: ResolveFunction IdeState TypeLensesResolve 'Method_CodeLensResolve
codeLensResolveProvider ideState pId lens@CodeLens{_range} uri TypeLensesResolve = do
nfp <- getNormalizedFilePathE uri
(gblSigs@(GlobalBindingTypeSigsResult _), pm) <-
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ atPoint IdeOptions{} (HAR _ hf _ _ (kind :: HieKind hietype)) (DKMap dm km) env

-- Check for evidence bindings
isInternal :: (Identifier, IdentifierDetails a) -> Bool
isInternal (Right _, dets) =
isInternal (Right _, _dets) =
#if MIN_VERSION_ghc(9,0,1)
any isEvidenceContext $ identInfo dets
any isEvidenceContext $ identInfo _dets
#else
False
#endif
Expand Down
Loading

0 comments on commit ccd80e8

Please sign in to comment.