Commit 128078e0 authored by Simon Marlow's avatar Simon Marlow

Keep the flag lists as IntSets rather than lists

This improves compile times slightly.
parent 122629e8
......@@ -14,7 +14,7 @@ import Name
import Fingerprint
-- import Outputable
import Data.List (sort)
import qualified Data.IntSet as IntSet
import System.FilePath (normalise)
-- | Produce a fingerprint of a @DynFlags@ value. We only base
......@@ -31,7 +31,7 @@ fingerprintDynFlags DynFlags{..} nameio =
-- *all* the extension flags and the language
lang = (fmap fromEnum language,
sort $ map fromEnum $ extensionFlags)
IntSet.toList $ extensionFlags)
-- -I, -D and -U flags affect CPP
cpp = (map normalise includePaths, sOpt_P settings)
......
......@@ -129,6 +129,9 @@ import qualified Data.Set as Set
import System.FilePath
import System.IO ( stderr, hPutChar )
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
-- -----------------------------------------------------------------------------
-- DynFlags
......@@ -304,7 +307,7 @@ data DynFlag
| Opt_DistrustAllPackages
| Opt_PackageTrust
deriving (Eq, Show)
deriving (Eq, Show, Enum)
data WarningFlag =
Opt_WarnDuplicateExports
......@@ -341,7 +344,7 @@ data WarningFlag =
| Opt_WarnAlternativeLayoutRuleTransitional
| Opt_WarnUnsafe
| Opt_WarnSafe
deriving (Eq, Show)
deriving (Eq, Show, Enum)
data Language = Haskell98 | Haskell2010
deriving Enum
......@@ -552,8 +555,8 @@ data DynFlags = DynFlags {
generatedDumps :: IORef (Set FilePath),
-- hsc dynamic flags
flags :: [DynFlag],
warningFlags :: [WarningFlag],
flags :: IntSet,
warningFlags :: IntSet,
-- Don't change this without updating extensionFlags:
language :: Maybe Language,
-- | Safe Haskell mode
......@@ -569,7 +572,7 @@ data DynFlags = DynFlags {
extensions :: [OnOff ExtensionFlag],
-- extensionFlags should always be equal to
-- flattenExtensionFlags language extensions
extensionFlags :: [ExtensionFlag],
extensionFlags :: IntSet,
-- | Message output action: use "ErrUtils" instead of this if you can
log_action :: LogAction,
......@@ -894,8 +897,8 @@ defaultDynFlags mySettings =
dirsToClean = panic "defaultDynFlags: No dirsToClean",
generatedDumps = panic "defaultDynFlags: No generatedDumps",
haddockOptions = Nothing,
flags = defaultFlags,
warningFlags = standardWarnings,
flags = IntSet.fromList (map fromEnum defaultFlags),
warningFlags = IntSet.fromList (map fromEnum standardWarnings),
language = Nothing,
safeHaskell = Sf_SafeInfered,
thOnLoc = noSrcSpan,
......@@ -938,12 +941,11 @@ data OnOff a = On a
-- OnOffs accumulate in reverse order, so we use foldr in order to
-- process them in the right order
flattenExtensionFlags :: Maybe Language -> [OnOff ExtensionFlag]
-> [ExtensionFlag]
flattenExtensionFlags :: Maybe Language -> [OnOff ExtensionFlag] -> IntSet
flattenExtensionFlags ml = foldr f defaultExtensionFlags
where f (On f) flags = f : delete f flags
f (Off f) flags = delete f flags
defaultExtensionFlags = languageExtensions ml
where f (On f) flags = IntSet.insert (fromEnum f) flags
f (Off f) flags = IntSet.delete (fromEnum f) flags
defaultExtensionFlags = IntSet.fromList (map fromEnum (languageExtensions ml))
languageExtensions :: Maybe Language -> [ExtensionFlag]
......@@ -985,31 +987,31 @@ languageExtensions (Just Haskell2010)
-- | Test whether a 'DynFlag' is set
dopt :: DynFlag -> DynFlags -> Bool
dopt f dflags = f `elem` (flags dflags)
dopt f dflags = fromEnum f `IntSet.member` flags dflags
-- | Set a 'DynFlag'
dopt_set :: DynFlags -> DynFlag -> DynFlags
dopt_set dfs f = dfs{ flags = f : flags dfs }
dopt_set dfs f = dfs{ flags = IntSet.insert (fromEnum f) (flags dfs) }
-- | Unset a 'DynFlag'
dopt_unset :: DynFlags -> DynFlag -> DynFlags
dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
dopt_unset dfs f = dfs{ flags = IntSet.delete (fromEnum f) (flags dfs) }
-- | Test whether a 'WarningFlag' is set
wopt :: WarningFlag -> DynFlags -> Bool
wopt f dflags = f `elem` (warningFlags dflags)
wopt f dflags = fromEnum f `IntSet.member` warningFlags dflags
-- | Set a 'WarningFlag'
wopt_set :: DynFlags -> WarningFlag -> DynFlags
wopt_set dfs f = dfs{ warningFlags = f : warningFlags dfs }
wopt_set dfs f = dfs{ warningFlags = IntSet.insert (fromEnum f) (warningFlags dfs) }
-- | Unset a 'WarningFlag'
wopt_unset :: DynFlags -> WarningFlag -> DynFlags
wopt_unset dfs f = dfs{ warningFlags = filter (/= f) (warningFlags dfs) }
wopt_unset dfs f = dfs{ warningFlags = IntSet.delete (fromEnum f) (warningFlags dfs) }
-- | Test whether a 'ExtensionFlag' is set
xopt :: ExtensionFlag -> DynFlags -> Bool
xopt f dflags = f `elem` extensionFlags dflags
xopt f dflags = fromEnum f `IntSet.member` extensionFlags dflags
-- | Set a 'ExtensionFlag'
xopt_set :: DynFlags -> ExtensionFlag -> DynFlags
......@@ -1589,9 +1591,9 @@ dynamic_flags = [
, Flag "Werror" (NoArg (setDynFlag Opt_WarnIsError))
, Flag "Wwarn" (NoArg (unSetDynFlag Opt_WarnIsError))
, Flag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
, Flag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = []})
, Flag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
deprecate "Use -w instead"))
, Flag "w" (NoArg (upd (\dfs -> dfs {warningFlags = []})))
, Flag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
------ Plugin flags ------------------------------------------------
, Flag "fplugin-opt" (hasArg addPluginModuleNameOption)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment