Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Cabal-syntax/src/Distribution/FieldGrammar/Class.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE QuantifiedConstraints #-}
Comment thread
Bodigrim marked this conversation as resolved.
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableSuperClasses #-}
Expand All @@ -13,6 +15,7 @@ module Distribution.FieldGrammar.Class
, defaultFreeTextFieldDefST
) where

import Data.Kind (Constraint, Type)
import Distribution.Compat.Lens
import Distribution.Compat.Prelude
import Prelude ()
Expand All @@ -23,23 +26,22 @@ import Distribution.FieldGrammar.Newtypes
import Distribution.Fields.Field
import Distribution.Utils.ShortText

-- | 'FieldGrammar' is parametrised by
-- | @g@ is parametrised by
--
-- * @s@ which is a structure we are parsing. We need this to provide prettyprinter
-- functionality
--
-- * @a@ type of the field.
--
-- /Note:/ We'd like to have @forall s. Applicative (f s)@ context.
class
( c SpecVersion
, c TestedWith
, c SpecLicense
, c Token
, c Token'
, c FilePathNT
, forall s. Applicative (g s)
) =>
FieldGrammar c g
FieldGrammar (c :: Type -> Constraint) (g :: Type -> Type -> Type)
| g -> c
where
-- | Unfocus, zoom out, /blur/ 'FieldGrammar'.
Expand Down Expand Up @@ -209,7 +211,7 @@ optionalField fn l = optionalFieldAla fn Identity l

-- | Optional field with default value.
optionalFieldDef
:: (FieldGrammar c g, Functor (g s), c (Identity a), Eq a)
:: (FieldGrammar c g, c (Identity a), Eq a)
=> FieldName
-- ^ field name
-> ALens' s a
Expand All @@ -231,7 +233,7 @@ monoidalField fn l = monoidalFieldAla fn Identity l

-- | Default implementation for 'freeTextFieldDefST'.
defaultFreeTextFieldDefST
:: (Functor (g s), FieldGrammar c g)
:: FieldGrammar c g
=> FieldName
-> ALens' s ShortText
-- ^ lens into the field
Expand Down
28 changes: 7 additions & 21 deletions Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ import qualified Distribution.Types.Lens as L

packageDescriptionFieldGrammar
:: ( FieldGrammar c g
, Applicative (g PackageDescription)
, Applicative (g PackageIdentifier)
, c (Identity BuildType)
, c (Identity PackageName)
, c (Identity Version)
Expand Down Expand Up @@ -166,8 +164,6 @@ packageDescriptionFieldGrammar =

libraryFieldGrammar
:: ( FieldGrammar c g
, Applicative (g Library)
, Applicative (g BuildInfo)
, c (Identity LibraryVisibility)
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
Expand Down Expand Up @@ -220,8 +216,6 @@ libraryFieldGrammar n =

foreignLibFieldGrammar
:: ( FieldGrammar c g
, Applicative (g ForeignLib)
, Applicative (g BuildInfo)
, c (Identity ForeignLibType)
, c (Identity LibVersionInfo)
, c (Identity Version)
Expand Down Expand Up @@ -267,8 +261,6 @@ foreignLibFieldGrammar n =

executableFieldGrammar
:: ( FieldGrammar c g
, Applicative (g Executable)
, Applicative (g BuildInfo)
, c (Identity ExecutableScope)
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
Expand Down Expand Up @@ -343,8 +335,6 @@ testStanzaCodeGenerators f s = fmap (\x -> s{_testStanzaCodeGenerators = x}) (f

testSuiteFieldGrammar
:: ( FieldGrammar c g
, Applicative (g TestSuiteStanza)
, Applicative (g BuildInfo)
, c (Identity ModuleName)
, c (Identity TestType)
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
Expand Down Expand Up @@ -493,8 +483,6 @@ benchmarkStanzaBuildInfo f s = fmap (\x -> s{_benchmarkStanzaBuildInfo = x}) (f

benchmarkFieldGrammar
:: ( FieldGrammar c g
, Applicative (g BenchmarkStanza)
, Applicative (g BuildInfo)
, c (Identity BenchmarkType)
, c (Identity ModuleName)
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
Expand Down Expand Up @@ -603,7 +591,6 @@ unvalidateBenchmark b =

buildInfoFieldGrammar
:: ( FieldGrammar c g
, Applicative (g BuildInfo)
, c (List CommaFSep (Identity ExeDependency) ExeDependency)
, c (List CommaFSep (Identity LegacyExeDependency) LegacyExeDependency)
, c (List CommaFSep (Identity PkgconfigDependency) PkgconfigDependency)
Expand Down Expand Up @@ -717,7 +704,6 @@ buildInfoFieldGrammar =

hsSourceDirsGrammar
:: ( FieldGrammar c g
, Applicative (g BuildInfo)
, c (List FSep (SymbolicPathNT Pkg (Dir Source)) (SymbolicPath Pkg (Dir Source)))
)
=> g BuildInfo [SymbolicPath Pkg (Dir Source)]
Expand All @@ -734,7 +720,7 @@ hsSourceDirsGrammar =
wrongLens f bi = (\fps -> set L.hsSourceDirs fps bi) <$> f []

optionsFieldGrammar
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
=> g BuildInfo (PerCompilerFlavor [String])
optionsFieldGrammar =
PerCompilerFlavor
Expand All @@ -751,7 +737,7 @@ optionsFieldGrammar =
extract flavor = L.options . lookupLens flavor

profOptionsFieldGrammar
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
=> g BuildInfo (PerCompilerFlavor [String])
profOptionsFieldGrammar =
PerCompilerFlavor
Expand All @@ -762,7 +748,7 @@ profOptionsFieldGrammar =
extract flavor = L.profOptions . lookupLens flavor

sharedOptionsFieldGrammar
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
=> g BuildInfo (PerCompilerFlavor [String])
sharedOptionsFieldGrammar =
PerCompilerFlavor
Expand All @@ -773,7 +759,7 @@ sharedOptionsFieldGrammar =
extract flavor = L.sharedOptions . lookupLens flavor

profSharedOptionsFieldGrammar
:: (FieldGrammar c g, Applicative (g BuildInfo), c (List NoCommaFSep Token' String))
:: (FieldGrammar c g, c (List NoCommaFSep Token' String))
=> g BuildInfo (PerCompilerFlavor [String])
profSharedOptionsFieldGrammar =
PerCompilerFlavor
Expand All @@ -796,7 +782,7 @@ lookupLens k f p@(PerCompilerFlavor ghc ghcjs)
-------------------------------------------------------------------------------

flagFieldGrammar
:: (FieldGrammar c g, Applicative (g PackageFlag))
:: FieldGrammar c g
=> FlagName
-> g PackageFlag PackageFlag
flagFieldGrammar name =
Expand All @@ -812,7 +798,7 @@ flagFieldGrammar name =
-------------------------------------------------------------------------------

sourceRepoFieldGrammar
:: (FieldGrammar c g, Applicative (g SourceRepo), c (Identity RepoType), c Token, c FilePathNT)
:: (FieldGrammar c g, c (Identity RepoType), c Token, c FilePathNT)
=> RepoKind
-> g SourceRepo SourceRepo
sourceRepoFieldGrammar kind =
Expand All @@ -831,7 +817,7 @@ sourceRepoFieldGrammar kind =
-------------------------------------------------------------------------------

setupBInfoFieldGrammar
:: (FieldGrammar c g, Functor (g SetupBuildInfo), c (List CommaVCat (Identity Dependency) Dependency))
:: (FieldGrammar c g, c (List CommaVCat (Identity Dependency) Dependency))
=> Bool
-> g SetupBuildInfo SetupBuildInfo
setupBInfoFieldGrammar def =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ f <@> x = f <*> x

ipiFieldGrammar
:: ( FieldGrammar c g
, Applicative (g InstalledPackageInfo)
, Applicative (g Basic)
, c (Identity AbiHash)
, c (Identity LibraryVisibility)
, c (Identity PackageName)
Expand Down Expand Up @@ -301,7 +299,6 @@ basicLibVisibility f b =

basicFieldGrammar
:: ( FieldGrammar c g
, Applicative (g Basic)
, c (Identity LibraryVisibility)
, c (Identity PackageName)
, c (Identity UnqualComponentName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ cabalInstallID =
-------------------------------------------------------------------------------

fieldDescrs
:: ( Applicative (g BuildReport)
, FieldGrammar c g
:: ( FieldGrammar c g
, c (Identity Arch)
, c (Identity CompilerId)
, c (Identity FlagAssignment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ clientInstallOptions _ =

clientInstallFlagsGrammar
:: ( FieldGrammar c g
, Applicative (g ClientInstallFlags)
, c (Identity (Flag Bool))
, c (Flag' FilePathNT FilePath)
, c (Identity (Flag OverwritePolicy))
Expand Down
2 changes: 0 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,6 @@ legacyPackageConfigFieldDescrs =

legacyPackageConfigFGSectionDescrs
:: ( FieldGrammar c g
, Applicative (g SourceRepoList)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
Expand Down Expand Up @@ -1837,7 +1836,6 @@ legacyPackageConfigSectionDescrs =

packageRepoSectionDescr
:: ( FieldGrammar c g
, Applicative (g SourceRepoList)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
Expand Down
1 change: 0 additions & 1 deletion cabal-install/src/Distribution/Client/Types/SourceRepo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ srpCommandLensNE f s = fmap (\x -> s{srpCommand = maybe [] toList x}) (f (nonEmp

sourceRepositoryPackageGrammar
:: ( FieldGrammar c g
, Applicative (g SourceRepoList)
, c (Identity RepoType)
, c (List NoCommaFSep FilePathNT String)
, c (NonEmpty' NoCommaFSep Token String)
Expand Down
7 changes: 7 additions & 0 deletions changelog.d/pr-11821.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
synopsis: Require `Applicative (g s)` as a superclass of `FieldGrammar`
packages: [Cabal-syntax,cabal-install]
prs: 11821
---

This allows us to scrap a bit of boilerplate.
Loading