diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index 4488c23cb8..643bcf6303 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -467,7 +467,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do let sessionOpts :: (Maybe FilePath, FilePath) -> IO (IdeResult HscEnvEq, [FilePath]) sessionOpts (hieYaml, file) = do - v <- fromMaybe HM.empty . Map.lookup hieYaml <$> readVar fileToFlags + v <- Map.findWithDefault HM.empty hieYaml <$> readVar fileToFlags cfp <- makeAbsolute file case HM.lookup (toNormalizedFilePath' cfp) v of Just (opts, old_di) -> do diff --git a/ghcide/src/Development/IDE/Import/DependencyInformation.hs b/ghcide/src/Development/IDE/Import/DependencyInformation.hs index 6f85af7678..b1d261f16d 100644 --- a/ghcide/src/Development/IDE/Import/DependencyInformation.hs +++ b/ghcide/src/Development/IDE/Import/DependencyInformation.hs @@ -166,7 +166,7 @@ data ModuleParseError = ModuleParseError instance NFData ModuleParseError -- | Error when trying to locate a module. -data LocateError = LocateError [Diagnostic] +newtype LocateError = LocateError [Diagnostic] deriving (Eq, Show, Generic) instance NFData LocateError @@ -316,7 +316,7 @@ transitiveReverseDependencies file DependencyInformation{..} = do where go :: Int -> IntSet -> IntSet go k i = - let outwards = fromMaybe IntSet.empty (IntMap.lookup k depReverseModuleDeps) + let outwards = IntMap.findWithDefault IntSet.empty k depReverseModuleDeps res = IntSet.union i outwards new = IntSet.difference i outwards in IntSet.foldr go res new diff --git a/ghcide/src/Development/IDE/Types/Logger.hs b/ghcide/src/Development/IDE/Types/Logger.hs index 05975a59c9..c40ef36e54 100644 --- a/ghcide/src/Development/IDE/Types/Logger.hs +++ b/ghcide/src/Development/IDE/Types/Logger.hs @@ -31,7 +31,7 @@ data Priority -- | Note that this is logging actions _of the program_, not of the user. -- You shouldn't call warning/error if the user has caused an error, only -- if our code has gone wrong and is itself erroneous (e.g. we threw an exception). -data Logger = Logger {logPriority :: Priority -> T.Text -> IO ()} +newtype Logger = Logger {logPriority :: Priority -> T.Text -> IO ()} instance Semigroup Logger where l1 <> l2 = Logger $ \p t -> logPriority l1 p t >> logPriority l2 p t diff --git a/hls-graph/src/Control/Concurrent/STM/Stats.hs b/hls-graph/src/Control/Concurrent/STM/Stats.hs index 548b3681ab..f8ca99bf04 100644 --- a/hls-graph/src/Control/Concurrent/STM/Stats.hs +++ b/hls-graph/src/Control/Concurrent/STM/Stats.hs @@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} module Control.Concurrent.STM.Stats ( atomicallyNamed diff --git a/hls-graph/src/Development/IDE/Graph.hs b/hls-graph/src/Development/IDE/Graph.hs index 1561abc35b..9f70b9f61b 100644 --- a/hls-graph/src/Development/IDE/Graph.hs +++ b/hls-graph/src/Development/IDE/Graph.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE PatternSynonyms #-} - module Development.IDE.Graph( shakeOptions, Rules, diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Action.hs b/hls-graph/src/Development/IDE/Graph/Internal/Action.hs index 5deadb5f98..2bb22a9c54 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Action.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Action.hs @@ -1,5 +1,4 @@ {-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs index 1ea7d9cde7..e83690e1c8 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Database.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Database.hs @@ -4,12 +4,9 @@ {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} module Development.IDE.Graph.Internal.Database (newDatabase, incDatabase, build, getDirtySet, getKeysAndVisitAge) where diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Options.hs b/hls-graph/src/Development/IDE/Graph/Internal/Options.hs index 33b5daa9af..df6b8b1711 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Options.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Options.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE RecordWildCards #-} - module Development.IDE.Graph.Internal.Options where import Control.Monad.Trans.Reader diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs b/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs index 0823070216..78db2e5f05 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Profile.hs @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ViewPatterns #-} {- HLINT ignore "Redundant bracket" -} -- a result of CPP expansion diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Rules.hs b/hls-graph/src/Development/IDE/Graph/Internal/Rules.hs index 3a580ab6be..f628a20479 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Rules.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Rules.hs @@ -1,9 +1,7 @@ -- We deliberately want to ensure the function we add to the rule database -- has the constraints we need on it when we get it out. {-# OPTIONS_GHC -Wno-redundant-constraints #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE BangPatterns #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RecordWildCards #-} @@ -44,7 +42,7 @@ addRule f = do f2 (Key a) b c = do v <- f (fromJust $ cast a :: key) b c v <- liftIO $ evaluate v - pure $ (Value . toDyn) <$> v + pure $ Value . toDyn <$> v runRule :: TheRules -> Key -> Maybe BS.ByteString -> RunMode -> Action (RunResult Value) diff --git a/hls-plugin-api/src/Ide/Plugin/Properties.hs b/hls-plugin-api/src/Ide/Plugin/Properties.hs index 684dafe2d5..2201cf2a53 100644 --- a/hls-plugin-api/src/Ide/Plugin/Properties.hs +++ b/hls-plugin-api/src/Ide/Plugin/Properties.hs @@ -3,10 +3,8 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index 924e92dabb..ae9a7d93f9 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -178,7 +178,7 @@ getClientConfig = getConfig getPluginConfig :: MonadLsp Config m => PluginId -> m PluginConfig getPluginConfig plugin = do config <- getClientConfig - return $ flip configForPlugin plugin config + return $ configForPlugin config plugin -- --------------------------------------------------------------------- diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index 44e2c080d6..ce184905d3 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -249,7 +249,7 @@ instance PluginMethod TextDocumentCompletion where combineResponses _ conf _ _ (toList -> xs) = snd $ consumeCompletionResponse limit $ combine xs where limit = maxCompletions conf - combine :: [List CompletionItem |? CompletionList] -> ((List CompletionItem) |? CompletionList) + combine :: [List CompletionItem |? CompletionList] -> (List CompletionItem |? CompletionList) combine cs = go True mempty cs go !comp acc [] = diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 5ecbab38b6..2a7f998018 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -3,11 +3,9 @@ {-# LANGUAGE ExtendedDefaultRules #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 94213dc183..e6b3e3a5b7 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -70,7 +70,7 @@ importLensCommand = PluginCommand importCommandId "Explicit import command" runImportCommand -- | The type of the parameters accepted by our command -data ImportCommandParams = ImportCommandParams WorkspaceEdit +newtype ImportCommandParams = ImportCommandParams WorkspaceEdit deriving (Generic) deriving anyclass (FromJSON, ToJSON) diff --git a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs index f012da8ecf..f48c40959a 100644 --- a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs +++ b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs @@ -515,7 +515,7 @@ deriving instance ToJSON RewriteSpec data QualName = QualName {qual, name :: String} deriving (Eq, Show, Generic, FromJSON, ToJSON) -data IE name +newtype IE name = IEVar name deriving (Eq, Show, Generic, FromJSON, ToJSON) diff --git a/plugins/hls-tactics-plugin/src/Refinery/Future.hs b/plugins/hls-tactics-plugin/src/Refinery/Future.hs index 51d844b3b4..e829672831 100644 --- a/plugins/hls-tactics-plugin/src/Refinery/Future.hs +++ b/plugins/hls-tactics-plugin/src/Refinery/Future.hs @@ -113,7 +113,7 @@ streamProofs s p = ListT $ go s [] pure p -- This would happen when we had a handler that wasn't followed by an error call. -- pair >> goal >>= \g -> (handler_ $ \_ -> traceM $ "Handling " <> show g) <|> failure "Error" -- We would see the "Handling a" message when solving for b. - (go s' (goals ++ [(meta, goal)]) pure $ k h) + go s' (goals ++ [(meta, goal)]) pure $ k h go s goals handlers (Effect m) = m >>= go s goals handlers go s goals handlers (Stateful f) = let (s', p) = f s @@ -121,10 +121,10 @@ streamProofs s p = ListT $ go s [] pure p go s goals handlers (Alt p1 p2) = unListT $ ListT (go s goals handlers p1) <|> ListT (go s goals handlers p2) go s goals handlers (Interleave p1 p2) = - interleaveT <$> (go s goals handlers p1) <*> (go s goals handlers p2) + interleaveT <$> go s goals handlers p1 <*> go s goals handlers p2 go s goals handlers (Commit p1 p2) = do solns <- force =<< go s goals handlers p1 - if (any isRight solns) then pure $ ofList solns else go s goals handlers p2 + if any isRight solns then pure $ ofList solns else go s goals handlers p2 go _ _ _ Empty = pure Done go _ _ handlers (Failure err _) = do annErr <- handlers err diff --git a/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP.hs b/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP.hs index a7b83f0fd4..4e8200042a 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP.hs @@ -1,6 +1,5 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE NoMonoLocalBinds #-} @@ -99,7 +98,7 @@ runContinuation plId cont state (fc, b) = do res <- c_runCommand cont env args fc b -- This block returns a maybe error. - fmap (maybe (Right $ A.Null) Left . coerce . foldMap Last) $ + fmap (maybe (Right A.Null) Left . coerce . foldMap Last) $ for res $ \case ErrorMessages errs -> do traverse_ showUserFacingMessage errs @@ -119,7 +118,7 @@ runContinuation plId cont state (fc, b) = do } Right edits -> do sendEdits edits - pure $ Nothing + pure Nothing ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP/TacticActions.hs b/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP/TacticActions.hs index 01ddfe4fe1..181a42cae6 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP/TacticActions.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/AbstractLSP/TacticActions.hs @@ -161,8 +161,8 @@ graftDecl dflags dst ix make_decl (L src (AMatch (FunRhs (L _ name) _ _) pats _) | dst `isSubspanOf` src = do L _ dec <- annotateDecl dflags $ make_decl name pats case dec of - ValD _ (FunBind { fun_matches = MG { mg_alts = L _ alts@(first_match : _)} - }) -> do + ValD _ FunBind{ fun_matches = MG { mg_alts = L _ alts@(first_match : _)} + } -> do -- For whatever reason, ExactPrint annotates newlines to the ends of -- case matches and type signatures, but only allows us to insert -- them at the beginning of those things. Thus, we need want to diff --git a/plugins/hls-tactics-plugin/src/Wingman/CaseSplit.hs b/plugins/hls-tactics-plugin/src/Wingman/CaseSplit.hs index 180229cf02..373fc9b23b 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/CaseSplit.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/CaseSplit.hs @@ -105,5 +105,5 @@ splitToDecl fixity name ams = do iterateSplit :: AgdaMatch -> [AgdaMatch] iterateSplit am = let iterated = iterate (agdaSplit =<<) $ pure am - in fmap wildify . head . drop 5 $ iterated + in fmap wildify . (!! 5) $ iterated diff --git a/plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs b/plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs index 5f2f86605c..add592ec00 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/CodeGen.hs @@ -2,7 +2,6 @@ {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} -{-# LANGUAGE TypeApplications #-} module Wingman.CodeGen ( module Wingman.CodeGen @@ -141,8 +140,7 @@ mkDestructPat already_in_scope con names in (names', ) $ ConPatIn (noLoc $ Unqual $ occName $ conLikeName con) $ RecCon - $ HsRecFields rec_fields - $ Nothing + $ HsRecFields rec_fields Nothing | otherwise = (names, ) $ infixifyPatIfNecessary con $ conP @@ -208,7 +206,7 @@ patSynExTys ps = patSynExTyVars ps destruct' :: Bool -> (ConLike -> Judgement -> Rule) -> HyInfo CType -> Judgement -> Rule destruct' use_field_puns f hi jdg = do - when (isDestructBlacklisted jdg) $ cut -- throwError NoApplicableTactic + when (isDestructBlacklisted jdg) cut -- throwError NoApplicableTactic let term = hi_name hi ext <- destructMatches @@ -227,7 +225,7 @@ destruct' use_field_puns f hi jdg = do -- resulting matches. destructLambdaCase' :: Bool -> (ConLike -> Judgement -> Rule) -> Judgement -> Rule destructLambdaCase' use_field_puns f jdg = do - when (isDestructBlacklisted jdg) $ cut -- throwError NoApplicableTactic + when (isDestructBlacklisted jdg) cut -- throwError NoApplicableTactic let g = jGoal jdg case splitFunTy_maybe (unCType g) of Just (arg, _) | isAlgType arg -> @@ -320,8 +318,7 @@ nonrecLet occjdgs jdg = do occexts <- traverse newSubgoal $ fmap snd occjdgs ctx <- ask ext <- newSubgoal - $ introduce ctx (userHypothesis $ fmap (second jGoal) occjdgs) - $ jdg + $ introduce ctx (userHypothesis $ fmap (second jGoal) occjdgs) jdg pure $ fmap noLoc $ let' <$> traverse diff --git a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs index 5dcdee57c0..4c2768255f 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs @@ -17,6 +17,7 @@ module Wingman.Debug import Control.DeepSeq import Control.Exception +import Data.Either (fromRight) import qualified Debug.Trace import Development.IDE.GHC.Compat (PlainGhcException, Outputable(..), SDoc, showSDocUnsafe) import System.IO.Unsafe (unsafePerformIO) @@ -33,7 +34,7 @@ unsafeRender' sdoc = unsafePerformIO $ do -- We might not have unsafeGlobalDynFlags (like during testing), in which -- case GHC panics. Instead of crashing, let's just fail to print. !res <- try @PlainGhcException $ evaluate $ deepseq z z - pure $ either (const "") id res + pure $ fromRight "" res {-# NOINLINE unsafeRender' #-} traceMX :: (Monad m, Show a) => String -> a -> m () diff --git a/plugins/hls-tactics-plugin/src/Wingman/EmptyCase.hs b/plugins/hls-tactics-plugin/src/Wingman/EmptyCase.hs index 42c62cfc19..442ac0cb99 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/EmptyCase.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/EmptyCase.hs @@ -17,8 +17,7 @@ import Data.Maybe import Data.Monoid import qualified Data.Text as T import Data.Traversable -import Development.IDE (hscEnv) -import Development.IDE (realSrcSpanToRange) +import Development.IDE (hscEnv, realSrcSpanToRange) import Development.IDE.Core.RuleTypes import Development.IDE.Core.Shake (IdeState (..)) import Development.IDE.Core.UseStale @@ -81,7 +80,7 @@ emptyCaseInteraction = Interaction $ , edits ) ) - $ (\ _ _ _ we -> pure $ pure $ RawEdit we) + (\ _ _ _ we -> pure $ pure $ RawEdit we) scrutinzedType :: EmptyCaseSort Type -> Maybe Type @@ -115,9 +114,9 @@ graftMatchGroup -> Graft (Either String) ParsedSource graftMatchGroup ss l = hoistGraft (runExcept . runExceptString) $ graftExprWithM ss $ \case - L span (HsCase ext scrut mg@_) -> do + L span (HsCase ext scrut mg) -> do pure $ Just $ L span $ HsCase ext scrut $ mg { mg_alts = l } - L span (HsLamCase ext mg@_) -> do + L span (HsLamCase ext mg) -> do pure $ Just $ L span $ HsLamCase ext $ mg { mg_alts = l } (_ :: LHsExpr GhcPs) -> pure Nothing @@ -165,6 +164,6 @@ data EmptyCaseSort a emptyCaseQ :: GenericQ [(SrcSpan, EmptyCaseSort (HsExpr GhcTc))] emptyCaseQ = everything (<>) $ mkQ mempty $ \case L new_span (Case scrutinee []) -> pure (new_span, EmptyCase scrutinee) - L new_span (expr@(LamCase [])) -> pure (new_span, EmptyLamCase expr) + L new_span expr@(LamCase []) -> pure (new_span, EmptyLamCase expr) (_ :: LHsExpr GhcTc) -> mempty diff --git a/plugins/hls-tactics-plugin/src/Wingman/GHC.hs b/plugins/hls-tactics-plugin/src/Wingman/GHC.hs index 647d6cd60b..bd48252dec 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/GHC.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/GHC.hs @@ -96,10 +96,7 @@ freshTyvars t = do pure (tv, setTyVarUnique tv uniq) pure $ everywhere - (mkT $ \tv -> - case M.lookup tv reps of - Just tv' -> tv' - Nothing -> tv + (mkT $ \tv -> M.findWithDefault tv tv reps ) $ snd $ tcSplitForAllTyVars t @@ -195,7 +192,7 @@ pattern SingleLet bind pats val expr <- HsLet _ (L _ (HsValBinds _ (ValBinds _ (bagToList -> - [(L _ (FunBind _ (L _ bind) (MG _ (L _ [L _ (AMatch _ pats val)]) _) _ _))]) _))) + [L _ (FunBind _ (L _ bind) (MG _ (L _ [L _ (AMatch _ pats val)]) _) _ _)]) _))) (L _ expr) @@ -204,7 +201,7 @@ pattern SingleLet bind pats val expr <- pattern Lambda :: [Pat GhcPs] -> HsExpr GhcPs -> HsExpr GhcPs pattern Lambda pats body <- HsLam _ - (MG {mg_alts = L _ [L _ (AMatch _ pats body) ]}) + MG {mg_alts = L _ [L _ (AMatch _ pats body) ]} where -- If there are no patterns to bind, just stick in the body Lambda [] body = body @@ -232,7 +229,7 @@ pattern SinglePatMatch pat body <- unpackMatches :: PatCompattable p => [Match p (LHsExpr p)] -> Maybe [(Pat p, LHsExpr p)] unpackMatches [] = Just [] unpackMatches (SinglePatMatch pat body : matches) = - (:) <$> pure (pat, body) <*> unpackMatches matches + ((pat, body):) <$> unpackMatches matches unpackMatches _ = Nothing @@ -241,14 +238,14 @@ unpackMatches _ = Nothing pattern Case :: PatCompattable p => HsExpr p -> [(Pat p, LHsExpr p)] -> HsExpr p pattern Case scrutinee matches <- HsCase _ (L _ scrutinee) - (MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)}) + MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)} ------------------------------------------------------------------------------ -- | Like 'Case', but for lambda cases. pattern LamCase :: PatCompattable p => [(Pat p, LHsExpr p)] -> HsExpr p pattern LamCase matches <- HsLamCase _ - (MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)}) + MG {mg_alts = L _ (fmap unLoc -> unpackMatches -> Just matches)} ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/src/Wingman/Judgements.hs b/plugins/hls-tactics-plugin/src/Wingman/Judgements.hs index 1b5a88999b..0c12e5f7c4 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Judgements.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Judgements.hs @@ -140,7 +140,7 @@ hasPositionalAncestry -- otherwise nothing hasPositionalAncestry ancestors jdg name | not $ null ancestors - = case any (== name) ancestors of + = case name `elem` ancestors of True -> Just True False -> case M.lookup name $ jAncestryMap jdg of @@ -162,8 +162,7 @@ filterAncestry ancestry reason jdg = disallowing reason (M.keysSet $ M.filterWithKey go $ hyByName $ jHypothesis jdg) jdg where go name _ - = not - . isJust + = isNothing $ hasPositionalAncestry ancestry jdg name @@ -233,14 +232,12 @@ filterSameTypeFromOtherPositions dcon pos jdg = -- | Return the ancestry of a 'PatVal', or 'mempty' otherwise. getAncestry :: Judgement' a -> OccName -> Set OccName getAncestry jdg name = - case M.lookup name $ jPatHypothesis jdg of - Just pv -> pv_ancestry pv - Nothing -> mempty + maybe mempty pv_ancestry . M.lookup name $ jPatHypothesis jdg jAncestryMap :: Judgement' a -> Map OccName (Set OccName) jAncestryMap jdg = - flip M.map (jPatHypothesis jdg) pv_ancestry + M.map pv_ancestry (jPatHypothesis jdg) provAncestryOf :: Provenance -> Set OccName @@ -365,9 +362,7 @@ hyNamesInScope = M.keysSet . hyByName -- | Are there any top-level function argument bindings in this judgement? jHasBoundArgs :: Judgement' a -> Bool jHasBoundArgs - = not - . null - . filter (isTopLevel . hi_provenance) + = any (isTopLevel . hi_provenance) . unHypothesis . jLocalHypothesis diff --git a/plugins/hls-tactics-plugin/src/Wingman/Judgements/SYB.hs b/plugins/hls-tactics-plugin/src/Wingman/Judgements/SYB.hs index db6e6e02c9..909c9f4dc3 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Judgements/SYB.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Judgements/SYB.hs @@ -87,12 +87,12 @@ sameTypeModuloLastApp = metaprogramAtQ :: SrcSpan -> GenericQ [(SrcSpan, T.Text)] metaprogramAtQ ss = everythingContaining ss $ mkQ mempty $ \case - L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS $ program) + L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS program) (_ :: LHsExpr GhcTc) -> mempty metaprogramQ :: GenericQ [(SrcSpan, T.Text)] metaprogramQ = everything (<>) $ mkQ mempty $ \case - L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS $ program) + L new_span (WingmanMetaprogram program) -> pure (new_span, T.pack $ unpackFS program) (_ :: LHsExpr GhcTc) -> mempty diff --git a/plugins/hls-tactics-plugin/src/Wingman/Judgements/Theta.hs b/plugins/hls-tactics-plugin/src/Wingman/Judgements/Theta.hs index c2fccd4d7d..a3e23595fd 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Judgements/Theta.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Judgements/Theta.hs @@ -196,7 +196,7 @@ matchBinds _ _ = [] ------------------------------------------------------------------------------ -- | Extract evidence from a 'ConPatOut'. patBinds :: Pat GhcTc -> [PredType] -patBinds (ConPatOut { pat_dicts = dicts }) +patBinds ConPatOut{ pat_dicts = dicts } = fmap idType dicts patBinds _ = [] diff --git a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs index 8e6319d806..b73d69430c 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs @@ -1,7 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoMonoLocalBinds #-} @@ -230,7 +229,7 @@ judgementForHole state nfp range cfg = do -- KnownThings is just the instances in scope. There are no ranges -- involved, so it's not crucial to track ages. - let henv = untrackedStaleValue $ hscenv + let henv = untrackedStaleValue hscenv eps <- liftIO $ readIORef $ hsc_EPS $ hscEnv henv (jdg, ctx) <- liftMaybe $ mkJudgementAndContext cfg g binds new_rss tcg (hscEnv henv) eps @@ -279,7 +278,7 @@ mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgm evidence = getEvidenceAtHole (fmap (`RealSrcSpan` Nothing) tcg_rss) tcs cls_hy = foldMap evidenceToHypothesis evidence subst = ts_unifier $ evidenceToSubst evidence defaultTacticState - pure $ + pure ( disallowing AlreadyDestructed already_destructed $ fmap (CType . substTyAddInScope subst . unCType) $ mkFirstJudgement diff --git a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/Metaprogram.hs b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/Metaprogram.hs index 096ccc0b79..e853831a32 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/Metaprogram.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/Metaprogram.hs @@ -15,8 +15,7 @@ import Control.Monad.Trans.Maybe import Data.List (find) import Data.Maybe import qualified Data.Text as T -import Development.IDE (positionToRealSrcLoc) -import Development.IDE (realSrcSpanToRange) +import Development.IDE (positionToRealSrcLoc, realSrcSpanToRange) import Development.IDE.Core.Shake (IdeState (..)) import Development.IDE.Core.UseStale import Development.IDE.GHC.Compat hiding (empty) diff --git a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/TacticProviders.hs b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/TacticProviders.hs index 631baf58b7..013c6ccb5e 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/TacticProviders.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/LanguageServer/TacticProviders.hs @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} {-# OPTIONS_GHC -Wno-orphans #-} module Wingman.LanguageServer.TacticProviders @@ -139,8 +138,7 @@ commandProvider UseDataCon = withConfig $ \cfg -> filterTypeProjection ( guardLength (<= cfg_max_use_ctor_actions cfg) - . fromMaybe [] - . fmap fst + . maybe [] fst . tacticsGetDataCons ) $ \dcon -> provide UseDataCon @@ -272,7 +270,7 @@ withConfig tp tpd = tp (le_config $ tpd_lspEnv tpd) tpd -- given by 'provide' are always available. provide :: TacticCommand -> T.Text -> TacticProvider provide tc name _ = - pure $ (Metadata (tacticTitle tc name) (mkTacticKind tc) (tacticPreferred tc), name) + pure (Metadata (tacticTitle tc name) (mkTacticKind tc) (tacticPreferred tc), name) ------------------------------------------------------------------------------ @@ -314,7 +312,7 @@ destructFilter _ _ = False -- usual algebraic types, and when any of their data constructors are records. destructPunFilter :: Type -> Type -> Bool destructPunFilter _ (algebraicTyCon -> Just tc) = - any (not . null . dataConFieldLabels) $ tyConDataCons tc + not . all (null . dataConFieldLabels) $ tyConDataCons tc destructPunFilter _ _ = False diff --git a/plugins/hls-tactics-plugin/src/Wingman/Machinery.hs b/plugins/hls-tactics-plugin/src/Wingman/Machinery.hs index 56fd9f7b2e..44baec5a4b 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Machinery.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Machinery.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE RankNTypes #-} @@ -18,7 +17,7 @@ import Data.Generics (everything, gcount, mkQ) import Data.Generics.Product (field') import Data.List (sortBy) import qualified Data.Map as M -import Data.Maybe (mapMaybe, isJust) +import Data.Maybe (mapMaybe, isNothing) import Data.Monoid (getSum) import Data.Ord (Down (..), comparing) import qualified Data.Set as S @@ -69,14 +68,14 @@ newSubgoal j = do tacticToRule :: Judgement -> TacticsM () -> Rule -tacticToRule jdg (TacticT tt) = RuleT $ flip execStateT jdg tt >>= flip Subgoal Axiom +tacticToRule jdg (TacticT tt) = RuleT $ execStateT tt jdg >>= flip Subgoal Axiom consumeChan :: OutChan (Maybe a) -> IO [a] consumeChan chan = do tryReadChan chan >>= tryRead >>= \case Nothing -> pure [] - Just (Just a) -> (:) <$> pure a <*> consumeChan chan + Just (Just a) -> (a:) <$> consumeChan chan Just Nothing -> pure [] @@ -107,7 +106,7 @@ runTactic duration ctx jdg t = do (in_proofs, out_proofs) <- newChan (in_errs, out_errs) <- newChan timed_out <- - fmap (not. isJust) $ timeout duration $ consume stream $ \case + fmap isNothing $ timeout duration $ consume stream $ \case Left err -> writeChan in_errs $ Just err Right proof -> writeChan in_proofs $ Just proof writeChan in_proofs Nothing @@ -342,7 +341,7 @@ lookupNameInContext name = do getDefiningType :: TacticsM CType getDefiningType = do - calling_fun_name <- fst . head <$> asks ctxDefiningFuncs + calling_fun_name <- asks (fst . head . ctxDefiningFuncs) maybe (failure $ NotInScope calling_fun_name) pure diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs index a9bdb694d1..fed7e91bbd 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Lexer.hs @@ -1,7 +1,5 @@ {-# LANGUAGE DataKinds #-} -{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TypeApplications #-} module Wingman.Metaprogramming.Lexer where diff --git a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Parser.hs b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Parser.hs index 96c93da2d1..676c829d22 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Parser.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Parser.hs @@ -1,12 +1,12 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} module Wingman.Metaprogramming.Parser where import qualified Control.Monad.Combinators.Expr as P +import Data.Either (fromRight) import Data.Functor import Data.Maybe (listToMaybe) import qualified Data.Text as T @@ -415,7 +415,7 @@ oneTactic = tactic :: Parser (TacticsM ()) -tactic = flip P.makeExprParser operators oneTactic +tactic = P.makeExprParser oneTactic operators operators :: [[P.Operator Parser (TacticsM ())]] operators = @@ -473,7 +473,7 @@ attempt_it rsl ctx jdg program = parseMetaprogram :: T.Text -> TacticsM () parseMetaprogram - = either (const $ pure ()) id + = fromRight (pure ()) . P.runParser tacticProgram "" diff --git a/plugins/hls-tactics-plugin/src/Wingman/Naming.hs b/plugins/hls-tactics-plugin/src/Wingman/Naming.hs index 05f5c2b85a..975607da1d 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Naming.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Naming.hs @@ -156,8 +156,7 @@ mkTyConName tc = foldMap (fmap toLower . take 1) camels | otherwise = getStem - $ fmap toLower - $ name + $ fmap toLower name where occ = getOccName tc name = occNameString occ diff --git a/plugins/hls-tactics-plugin/src/Wingman/Plugin.hs b/plugins/hls-tactics-plugin/src/Wingman/Plugin.hs index 909ee6c26e..d01bdbbc92 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Plugin.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Plugin.hs @@ -1,6 +1,3 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} - -- | A plugin that uses tactics to synthesize code module Wingman.Plugin where diff --git a/plugins/hls-tactics-plugin/src/Wingman/Simplify.hs b/plugins/hls-tactics-plugin/src/Wingman/Simplify.hs index 882d4dd897..3f170401ee 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Simplify.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Simplify.hs @@ -19,11 +19,12 @@ import Wingman.GHC (containsHsVar, fromPatCompat, pattern SingleLet) pattern Lambda :: [Pat GhcPs] -> HsExpr GhcPs -> HsExpr GhcPs pattern Lambda pats body <- HsLam _ - (MG {mg_alts = L _ [L _ - (Match { m_pats = fmap fromPatCompat -> pats - , m_grhss = GRHSs {grhssGRHSs = [L _ ( + MG {mg_alts = L _ [L _ + Match { m_pats = fmap fromPatCompat -> pats + , m_grhss = GRHSs {grhssGRHSs = [L _ ( GRHS _ [] (L _ body))]} - })]}) + }] + } where -- If there are no patterns to bind, just stick in the body Lambda [] body = body @@ -35,9 +36,8 @@ pattern Lambda pats body <- -- | Simlify an expression. simplify :: LHsExpr GhcPs -> LHsExpr GhcPs simplify - = head - . drop 3 -- Do three passes; this should be good enough for the limited - -- amount of gas we give to auto + = (!!3) -- Do three passes; this should be good enough for the limited + -- amount of gas we give to auto . iterate (everywhere $ foldEndo [ simplifyEtaReduce , simplifyRemoveParens @@ -62,7 +62,7 @@ simplifyEtaReduce = mkT $ \case (HsVar _ (L _ a)) | pat == a -> var "id" Lambda - (unsnoc -> Just (pats, (VarPat _ (L _ pat)))) + (unsnoc -> Just (pats, VarPat _ (L _ pat))) (HsApp _ (L _ f) (L _ (HsVar _ (L _ a)))) | pat == a -- We can only perform this simplifiation if @pat@ is otherwise unused. @@ -84,8 +84,8 @@ simplifySingleLet = mkT $ \case simplifyCompose :: GenericT simplifyCompose = mkT $ \case Lambda - (unsnoc -> Just (pats, (VarPat _ (L _ pat)))) - (unroll -> (fs@(_:_), (HsVar _ (L _ a)))) + (unsnoc -> Just (pats, VarPat _ (L _ pat))) + (unroll -> (fs@(_:_), HsVar _ (L _ a))) | pat == a -- We can only perform this simplifiation if @pat@ is otherwise unused. , not (containsHsVar pat fs) -> diff --git a/plugins/hls-tactics-plugin/src/Wingman/StaticPlugin.hs b/plugins/hls-tactics-plugin/src/Wingman/StaticPlugin.hs index b773a60c52..82be432a3a 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/StaticPlugin.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/StaticPlugin.hs @@ -91,8 +91,7 @@ mkMetaprogram ss mp = $ L ss $ HsVar noExtField $ L ss - $ mkRdrUnqual - $ metaprogramHoleName + $ mkRdrUnqual metaprogramHoleName addMetaprogrammingSyntax :: Data a => a -> a diff --git a/plugins/hls-tactics-plugin/src/Wingman/Tactics.hs b/plugins/hls-tactics-plugin/src/Wingman/Tactics.hs index d6909a11ca..ef8025fd89 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Tactics.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Tactics.hs @@ -8,8 +8,7 @@ module Wingman.Tactics import Control.Applicative (Alternative(empty), (<|>)) import Control.Lens ((&), (%~), (<>~)) -import Control.Monad (filterM) -import Control.Monad (unless) +import Control.Monad (filterM, unless) import Control.Monad.Extra (anyM) import Control.Monad.Reader.Class (MonadReader (ask)) import Control.Monad.State.Strict (StateT(..), runStateT) @@ -95,7 +94,7 @@ recursion = requireConcreteHole $ tracing "recursion" $ do -- Make sure that the recursive call contains at least one already-bound -- pattern value. This ensures it is structurally smaller, and thus -- suggests termination. - case (any (flip M.member pat_vals) $ syn_used_vals ext) of + case any (flip M.member pat_vals) $ syn_used_vals ext of True -> Nothing False -> Just UnhelpfulRecursion @@ -233,7 +232,7 @@ homo hi = requireConcreteHole . tracing "homo" $ do -- Ensure that every data constructor in the domain type is covered in the -- codomain; otherwise 'homo' will produce an ill-typed program. - case (uncoveredDataCons (coerce $ hi_type hi) (coerce g)) of + case uncoveredDataCons (coerce $ hi_type hi) (coerce g) of Just uncovered_dcs -> unless (S.null uncovered_dcs) $ failure $ TacticPanic "Can't cover every datacon in domain" @@ -243,7 +242,7 @@ homo hi = requireConcreteHole . tracing "homo" $ do $ destruct' False (\dc jdg -> buildDataCon False jdg dc $ snd $ splitAppTys $ unCType $ jGoal jdg) - $ hi + hi ------------------------------------------------------------------------------ @@ -266,7 +265,7 @@ homoLambdaCase = $ jGoal jdg -data Saturation = Unsaturated Int +newtype Saturation = Unsaturated Int deriving (Eq, Ord, Show) pattern Saturated :: Saturation @@ -443,7 +442,7 @@ matching f = TacticT $ StateT $ \s -> runStateT (unTacticT $ f s) s attemptOn :: (Judgement -> [a]) -> (a -> TacticsM ()) -> TacticsM () -attemptOn getNames tac = matching (choice . fmap (\s -> tac s) . getNames) +attemptOn getNames tac = matching (choice . fmap tac . getNames) localTactic :: TacticsM a -> (Judgement -> Judgement) -> TacticsM a @@ -501,7 +500,7 @@ applyMethod cls df method_name = do applyByName :: OccName -> TacticsM () applyByName name = do g <- goal - choice $ (unHypothesis (jHypothesis g)) <&> \hi -> + choice $ unHypothesis (jHypothesis g) <&> \hi -> case hi_name hi == name of True -> apply Saturated hi False -> empty @@ -582,8 +581,7 @@ letBind occs = do $ \occ -> fmap (occ, ) $ fmap (<$ jdg) - $ fmap CType - $ newUnivar + $ fmap CType newUnivar rule $ nonrecLet occ_tys diff --git a/plugins/hls-tactics-plugin/src/Wingman/Types.hs b/plugins/hls-tactics-plugin/src/Wingman/Types.hs index 63c30a82ae..df64258f46 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Types.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Types.hs @@ -333,12 +333,12 @@ instance MonadExtract Int (Synthesized (LHsExpr GhcPs)) TacticError TacticState instance MonadReader r m => MonadReader r (TacticT jdg ext err s m) where - ask = TacticT $ lift $ Effect $ fmap pure ask + ask = TacticT $ lift $ Effect $ asks pure local f (TacticT m) = TacticT $ Strict.StateT $ \jdg -> Effect $ local f $ pure $ Strict.runStateT m jdg instance MonadReader r m => MonadReader r (RuleT jdg ext err s m) where - ask = RuleT $ Effect $ fmap Axiom ask + ask = RuleT $ Effect $ asks Axiom local f (RuleT m) = RuleT $ Effect $ local f $ pure m mkMetaHoleName :: Int -> RdrName @@ -463,7 +463,7 @@ data Context = Context } instance Show Context where - show (Context {..}) = mconcat + show Context{..} = mconcat [ "Context " , showsPrec 10 ctxDefiningFuncs "" , showsPrec 10 ctxModuleFuncs "" diff --git a/shake-bench/src/Development/Benchmark/Rules.hs b/shake-bench/src/Development/Benchmark/Rules.hs index 92f5c13f63..29e36fe71d 100644 --- a/shake-bench/src/Development/Benchmark/Rules.hs +++ b/shake-bench/src/Development/Benchmark/Rules.hs @@ -170,8 +170,8 @@ phonyRules prefix executableName prof buildFolder examples = do phony (prefix <> "all") $ do exampleTargets <- forM examples $ \ex -> allTargetsForExample prof buildFolder ex - need $ [ buildFolder profilingPath prof "results.csv" ] - ++ concat exampleTargets + need $ (buildFolder profilingPath prof "results.csv") + : concat exampleTargets phony (prefix <> "all-binaries") $ need =<< allBinaries buildFolder executableName -------------------------------------------------------------------------------- type OutputFolder = FilePath