Skip to content

Commit

Permalink
Merge pull request #6725 from phadej/disambiguate-flags
Browse files Browse the repository at this point in the history
Rename Flag types
  • Loading branch information
phadej authored Apr 21, 2020
2 parents c26cddb + 7fcb204 commit b89a1c6
Show file tree
Hide file tree
Showing 42 changed files with 199 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Cabal/Distribution/Backpack/ComponentsGraph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.PackageDescription
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Backpack/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import Distribution.Backpack.ReadyComponent
import Distribution.Backpack.ComponentsGraph
import Distribution.Backpack.Id

import Distribution.Simple.Compiler hiding (Flag)
import Distribution.Simple.Compiler
import Distribution.Package
import qualified Distribution.InstalledPackageInfo as Installed
import Distribution.InstalledPackageInfo (InstalledPackageInfo
,emptyInstalledPackageInfo)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.PackageDescription
import Distribution.ModuleName
import Distribution.Simple.Setup as Setup
import Distribution.Simple.LocalBuildInfo
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Backpack/ConfiguredComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Distribution.Types.LibraryName
import Distribution.Types.UnqualComponentName
import Distribution.Types.ComponentInclude
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.PackageDescription
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.Setup as Setup
import Distribution.Simple.LocalBuildInfo
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Backpack/Id.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Types.UnqualComponentName
import Distribution.Simple.Compiler hiding (Flag)
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.Simple.Compiler
import Distribution.PackageDescription
import Distribution.Simple.Setup as Setup
import qualified Distribution.Simple.InstallDirs as InstallDirs
import Distribution.Simple.LocalBuildInfo
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Backpack/LinkedComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Distribution.Types.ComponentInclude
import Distribution.Types.ComponentId
import Distribution.Types.PackageId
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.PackageDescription
import Distribution.ModuleName
import Distribution.Simple.LocalBuildInfo
import Distribution.Verbosity
Expand Down
12 changes: 6 additions & 6 deletions Cabal/Distribution/Fields/ConfVar.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{-# LANGUAGE OverloadedStrings #-}
module Distribution.Fields.ConfVar (parseConditionConfVar) where

import Distribution.Compat.CharParsing (char, integral)
import Distribution.Compat.CharParsing (char, integral)
import Distribution.Compat.Prelude
import Distribution.Parsec (Parsec (..), runParsecParser, Position (..))
import Distribution.Parsec.FieldLineStream (fieldLineStreamFromBS)
import Distribution.Fields.Field (SectionArg (..))
import Distribution.Fields.Field (SectionArg (..))
import Distribution.Fields.ParseResult
import Distribution.Parsec (Parsec (..), Position (..), runParsecParser)
import Distribution.Parsec.FieldLineStream (fieldLineStreamFromBS)
import Distribution.Types.Condition
import Distribution.Types.ConfVar (ConfVar (..))
import Distribution.Types.ConfVar (ConfVar (..))
import Distribution.Version
(anyVersion, earlierVersion, intersectVersionRanges, laterVersion, majorBoundVersion,
mkVersion, noVersion, orEarlierVersion, orLaterVersion, thisVersion, unionVersionRanges,
Expand Down Expand Up @@ -52,7 +52,7 @@ parser = condOr

boolLiteral = Lit <$> boolLiteral'
osCond = Var . OS <$ string "os" <*> parens fromParsec
flagCond = Var . Flag <$ string "flag" <*> parens fromParsec
flagCond = Var . PackageFlag <$ string "flag" <*> parens fromParsec
archCond = Var . Arch <$ string "arch" <*> parens fromParsec
implCond = Var <$ string "impl" <*> parens implCond'

Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Distribution.PackageDescription (

-- * package configuration
GenericPackageDescription(..),
Flag(..), emptyFlag,
PackageFlag(..), emptyFlag,
FlagName, mkFlagName, unFlagName,
FlagAssignment, mkFlagAssignment, unFlagAssignment,
nullFlagAssignment, showFlagValue,
Expand Down
16 changes: 8 additions & 8 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,12 @@ checkUnusedFlags gpd

used :: Set.Set FlagName
used = mconcat
[ toSetOf (L.condLibrary . traverse . traverseCondTreeV . L._Flag) gpd
, toSetOf (L.condSubLibraries . traverse . _2 . traverseCondTreeV . L._Flag) gpd
, toSetOf (L.condForeignLibs . traverse . _2 . traverseCondTreeV . L._Flag) gpd
, toSetOf (L.condExecutables . traverse . _2 . traverseCondTreeV . L._Flag) gpd
, toSetOf (L.condTestSuites . traverse . _2 . traverseCondTreeV . L._Flag) gpd
, toSetOf (L.condBenchmarks . traverse . _2 . traverseCondTreeV . L._Flag) gpd
[ toSetOf (L.condLibrary . traverse . traverseCondTreeV . L._PackageFlag) gpd
, toSetOf (L.condSubLibraries . traverse . _2 . traverseCondTreeV . L._PackageFlag) gpd
, toSetOf (L.condForeignLibs . traverse . _2 . traverseCondTreeV . L._PackageFlag) gpd
, toSetOf (L.condExecutables . traverse . _2 . traverseCondTreeV . L._PackageFlag) gpd
, toSetOf (L.condTestSuites . traverse . _2 . traverseCondTreeV . L._PackageFlag) gpd
, toSetOf (L.condBenchmarks . traverse . _2 . traverseCondTreeV . L._PackageFlag) gpd
]

checkUnicodeXFields :: GenericPackageDescription -> [PackageCheck]
Expand Down Expand Up @@ -1650,14 +1650,14 @@ checkDevelopmentOnlyFlags pkg =

-- We've basically got three-values logic here: True, False or unknown
-- hence this pattern to propagate the unknown cases properly.
definitelyFalse (Var (Flag n)) = maybe False not (Map.lookup n manualFlags)
definitelyFalse (Var (PackageFlag n)) = maybe False not (Map.lookup n manualFlags)
definitelyFalse (Var _) = False
definitelyFalse (Lit b) = not b
definitelyFalse (CNot c) = definitelyTrue c
definitelyFalse (COr c1 c2) = definitelyFalse c1 && definitelyFalse c2
definitelyFalse (CAnd c1 c2) = definitelyFalse c1 || definitelyFalse c2

definitelyTrue (Var (Flag n)) = fromMaybe False (Map.lookup n manualFlags)
definitelyTrue (Var (PackageFlag n)) = fromMaybe False (Map.lookup n manualFlags)
definitelyTrue (Var _) = False
definitelyTrue (Lit b) = b
definitelyTrue (CNot c) = definitelyFalse c
Expand Down
8 changes: 4 additions & 4 deletions Cabal/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ simplifyWithSysParams os arch cinfo cond = (cond', flags)
Just compat -> Right (any matchImpl compat)
where
matchImpl (CompilerId c v) = comp == c && v `withinRange` vr
interp (Flag f) = Left f
interp (PackageFlag f) = Left f

-- TODO: Add instances and check
--
Expand Down Expand Up @@ -125,7 +125,7 @@ parseCondition = condOr
boolLiteral = fmap Lit parsec
archIdent = fmap Arch parsec
osIdent = fmap OS parsec
flagIdent = fmap (Flag . mkFlagName . lowercase) (munch1 isIdentChar)
flagIdent = fmap (PackageFlag . mkFlagName . lowercase) (munch1 isIdentChar)
isIdentChar c = isAlphaNum c || c == '_' || c == '-'
oper s = sp >> string s >> sp
sp = spaces
Expand Down Expand Up @@ -327,7 +327,7 @@ fromDepMapUnion :: DepMapUnion -> [Dependency]
fromDepMapUnion m = [ Dependency p vr cs | (p,(vr,cs)) <- Map.toList (unDepMapUnion m) ]

freeVars :: CondTree ConfVar c a -> [FlagName]
freeVars t = [ f | Flag f <- freeVars' t ]
freeVars t = [ f | PackageFlag f <- freeVars' t ]
where
freeVars' (CondNode _ _ ifs) = concatMap compfv ifs
compfv (CondBranch c ct mct) = condfv c ++ freeVars' ct ++ maybe [] freeVars' mct
Expand Down Expand Up @@ -478,7 +478,7 @@ finalizePD userflags enabled satisfyDep
++ map (\(name,tree) -> mapTreeData (SubComp name . CTest) tree) tests0
++ map (\(name,tree) -> mapTreeData (SubComp name . CBench) tree) bms0

flagChoices = map (\(MkFlag n _ d manual) -> (n, d2c manual n d)) flags
flagChoices = map (\(MkPackageFlag n _ d manual) -> (n, d2c manual n d)) flags
d2c manual n b = case lookupFlagAssignment n userflags of
Just val -> [val]
Nothing
Expand Down
10 changes: 5 additions & 5 deletions Cabal/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ lookupLens k f p@(PerCompilerFlavor ghc ghcjs)
-------------------------------------------------------------------------------

flagFieldGrammar
:: (FieldGrammar g, Applicative (g Flag))
=> FlagName -> g Flag Flag
flagFieldGrammar name = MkFlag name
:: (FieldGrammar g, Applicative (g PackageFlag))
=> FlagName -> g PackageFlag PackageFlag
flagFieldGrammar name = MkPackageFlag name
<$> freeTextFieldDef "description" L.flagDescription
<*> booleanFieldDef "default" L.flagDefault True
<*> booleanFieldDef "manual" L.flagManual False
{-# SPECIALIZE flagFieldGrammar :: FlagName -> ParsecFieldGrammar' Flag #-}
{-# SPECIALIZE flagFieldGrammar :: FlagName -> PrettyFieldGrammar' Flag #-}
{-# SPECIALIZE flagFieldGrammar :: FlagName -> ParsecFieldGrammar' PackageFlag #-}
{-# SPECIALIZE flagFieldGrammar :: FlagName -> PrettyFieldGrammar' PackageFlag #-}

-------------------------------------------------------------------------------
-- SourceRepo
Expand Down
14 changes: 7 additions & 7 deletions Cabal/Distribution/PackageDescription/PrettyPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ ppSetupBInfo v (Just sbi)
| otherwise = pure $ PrettySection () "custom-setup" [] $
prettyFieldGrammar v (setupBInfoFieldGrammar False) sbi

ppGenPackageFlags :: CabalSpecVersion -> [Flag] -> [PrettyField ()]
ppGenPackageFlags :: CabalSpecVersion -> [PackageFlag] -> [PrettyField ()]
ppGenPackageFlags = map . ppFlag

ppFlag :: CabalSpecVersion -> Flag -> PrettyField ()
ppFlag v flag@(MkFlag name _ _ _) = PrettySection () "flag" [ppFlagName name] $
ppFlag :: CabalSpecVersion -> PackageFlag -> PrettyField ()
ppFlag v flag@(MkPackageFlag name _ _ _) = PrettySection () "flag" [ppFlagName name] $
prettyFieldGrammar v (flagFieldGrammar name) flag

ppCondTree2 :: CabalSpecVersion -> PrettyFieldGrammar' s -> CondTree ConfVar [Dependency] s -> [PrettyField ()]
Expand Down Expand Up @@ -176,10 +176,10 @@ ppCondition (COr c1 c2) = parens (hsep [ppCondition c1, text "|
ppCondition (CAnd c1 c2) = parens (hsep [ppCondition c1, text "&&"
<+> ppCondition c2])
ppConfVar :: ConfVar -> Doc
ppConfVar (OS os) = text "os" <<>> parens (pretty os)
ppConfVar (Arch arch) = text "arch" <<>> parens (pretty arch)
ppConfVar (Flag name) = text "flag" <<>> parens (ppFlagName name)
ppConfVar (Impl c v) = text "impl" <<>> parens (pretty c <+> pretty v)
ppConfVar (OS os) = text "os" <<>> parens (pretty os)
ppConfVar (Arch arch) = text "arch" <<>> parens (pretty arch)
ppConfVar (PackageFlag name) = text "flag" <<>> parens (ppFlagName name)
ppConfVar (Impl c v) = text "impl" <<>> parens (pretty c <+> pretty v)

ppFlagName :: FlagName -> Doc
ppFlagName = text . unFlagName
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ import Prelude ()
import Distribution.Compat.Prelude

-- local
import Distribution.Simple.Compiler hiding (Flag)
import Distribution.Simple.Compiler
import Distribution.Simple.UserHooks
import Distribution.Package
import Distribution.PackageDescription hiding (Flag)
import Distribution.PackageDescription
import Distribution.PackageDescription.Configuration
import Distribution.Simple.Program
import Distribution.Simple.Program.Db
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import Distribution.Simple.Build.Macros (generateCabalMacrosHeader)
import Distribution.Simple.Build.PathsModule (generatePathsModule)
import qualified Distribution.Simple.Program.HcPkg as HcPkg

import Distribution.Simple.Compiler hiding (Flag)
import Distribution.PackageDescription hiding (Flag)
import Distribution.Simple.Compiler
import Distribution.PackageDescription
import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import qualified Distribution.ModuleName as ModuleName
Expand Down
18 changes: 9 additions & 9 deletions Cabal/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module Distribution.Simple.Compiler (
flagToDebugInfoLevel,

-- * Support for language extensions
Flag,
CompilerFlag,
languageToFlags,
unsupportedLanguages,
extensionsToFlags,
Expand Down Expand Up @@ -93,9 +93,9 @@ data Compiler = Compiler {
compilerCompat :: [CompilerId],
-- ^ Other implementations that this compiler claims to be
-- compatible with.
compilerLanguages :: [(Language, Flag)],
compilerLanguages :: [(Language, CompilerFlag)],
-- ^ Supported language standards.
compilerExtensions :: [(Extension, Maybe Flag)],
compilerExtensions :: [(Extension, Maybe CompilerFlag)],
-- ^ Supported extensions.
compilerProperties :: Map String String
-- ^ A key-value map for properties not covered by the above fields.
Expand Down Expand Up @@ -279,12 +279,12 @@ unsupportedLanguages comp langs =
[ lang | lang <- langs
, isNothing (languageToFlag comp lang) ]

languageToFlags :: Compiler -> Maybe Language -> [Flag]
languageToFlags :: Compiler -> Maybe Language -> [CompilerFlag]
languageToFlags comp = filter (not . null)
. catMaybes . map (languageToFlag comp)
. maybe [Haskell98] (\x->[x])

languageToFlag :: Compiler -> Language -> Maybe Flag
languageToFlag :: Compiler -> Language -> Maybe CompilerFlag
languageToFlag comp ext = lookup ext (compilerLanguages comp)


Expand All @@ -294,16 +294,16 @@ unsupportedExtensions comp exts =
[ ext | ext <- exts
, isNothing (extensionToFlag' comp ext) ]

type Flag = String
type CompilerFlag = String

-- |For the given compiler, return the flags for the supported extensions.
extensionsToFlags :: Compiler -> [Extension] -> [Flag]
extensionsToFlags :: Compiler -> [Extension] -> [CompilerFlag]
extensionsToFlags comp = nub . filter (not . null)
. catMaybes . map (extensionToFlag comp)

-- | Looks up the flag for a given extension, for a given compiler.
-- Ignores the subtlety of extensions which lack associated flags.
extensionToFlag :: Compiler -> Extension -> Maybe Flag
extensionToFlag :: Compiler -> Extension -> Maybe CompilerFlag
extensionToFlag comp ext = join (extensionToFlag' comp ext)

-- | Looks up the flag for a given extension, for a given compiler.
Expand All @@ -315,7 +315,7 @@ extensionToFlag comp ext = join (extensionToFlag' comp ext)
-- the inner layer indicates whether it has a flag.
-- When building strings, it is often more convenient to use 'extensionToFlag',
-- which ignores the difference.
extensionToFlag' :: Compiler -> Extension -> Maybe (Maybe Flag)
extensionToFlag' :: Compiler -> Extension -> Maybe (Maybe CompilerFlag)
extensionToFlag' comp ext = lookup ext (compilerExtensions comp)

-- | Does this compiler support parallel --make mode?
Expand Down
Loading

0 comments on commit b89a1c6

Please sign in to comment.