summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-10-23 17:24:24 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-24 01:26:11 -0400
commit8300ca2e3bcc3e74f7524116f85688da6167bb2f (patch)
tree73722e3f5621c1a08c34c67b68b461bc0aa35070
parentdd2dba808aaa957c3d036b0025b412c499aace3d (diff)
downloadhaskell-8300ca2e3bcc3e74f7524116f85688da6167bb2f.tar.gz
driver: Export wWarningFlagMap
A new feature requires Ghcide to be able to convert warnings to CLI flags (WarningFlag -> String). This is most easily implemented in terms of the internal function flagSpecOf, which uses an inefficient implementation based on linear search through a linked list. This PR derives Ord for WarningFlag, and replaces that list with a Map. Closes #19087.
-rw-r--r--compiler/GHC/Driver/Flags.hs3
-rw-r--r--compiler/GHC/Driver/Session.hs8
2 files changed, 6 insertions, 5 deletions
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs
index e0ddaff52b..05733c88e4 100644
--- a/compiler/GHC/Driver/Flags.hs
+++ b/compiler/GHC/Driver/Flags.hs
@@ -536,7 +536,7 @@ data WarningFlag =
| Opt_WarnMissingKindSignatures -- Since 9.2
| Opt_WarnMissingExportedPatternSynonymSignatures -- since 9.2
| Opt_WarnRedundantStrictnessFlags -- Since 9.4
- deriving (Eq, Show, Enum)
+ deriving (Eq, Ord, Show, Enum)
-- | Return the names of a WarningFlag
--
@@ -787,4 +787,3 @@ unusedBindsFlags = [ Opt_WarnUnusedTopBinds
, Opt_WarnUnusedLocalBinds
, Opt_WarnUnusedPatternBinds
]
-
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 8f1cd31ece..aaedf4f2d7 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -268,6 +268,7 @@ import Data.Ord
import Data.Char
import Data.List (intercalate, sortBy)
import qualified Data.List.NonEmpty as NE
+import qualified Data.Map as Map
import qualified Data.Set as Set
import System.FilePath
import System.Directory
@@ -3084,9 +3085,10 @@ nop _ = return ()
-- | Find the 'FlagSpec' for a 'WarningFlag'.
flagSpecOf :: WarningFlag -> Maybe (FlagSpec WarningFlag)
-flagSpecOf flag = listToMaybe $ filter check wWarningFlags
- where
- check fs = flagSpecFlag fs == flag
+flagSpecOf = flip Map.lookup wWarningFlagMap
+
+wWarningFlagMap :: Map.Map WarningFlag (FlagSpec WarningFlag)
+wWarningFlagMap = Map.fromListWith (\_ x -> x) $ map (flagSpecFlag &&& id) wWarningFlags
-- | These @-W\<blah\>@ flags can all be reversed with @-Wno-\<blah\>@
wWarningFlags :: [FlagSpec WarningFlag]