Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Feb 26, 2024
1 parent 2920611 commit 6c19b98
Show file tree
Hide file tree
Showing 41 changed files with 338 additions and 313 deletions.
4 changes: 2 additions & 2 deletions Cabal-syntax/src/Distribution/FieldGrammar/Parsec.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | This module provides a 'FieldGrammarParser', one way to parse
-- @.cabal@ -like files.
Expand Down
1 change: 0 additions & 1 deletion Cabal-syntax/src/Distribution/ModuleName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ components mn = split (unModuleName mn)
(chunk, []) -> chunk : []
(chunk, _ : rest) -> chunk : split rest


-- | Construct a 'ModuleName' from valid module components, i.e. parts
-- separated by dots.
--
Expand Down
19 changes: 12 additions & 7 deletions Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,20 @@ unionVersionRanges' (vr, cs) (vr', cs') = (unionVersionRanges vr vr', cs <> cs')

toDepMapUnion :: Dependencies -> DepMapUnion
toDepMapUnion ds =
DepMapUnion $ Map.fromListWith unionVersionRanges'
([((p, Public), (vr, cs)) | Dependency p vr cs <- publicDependencies ds]
++ [((p, Private (private_alias d)), (vr, cs)) | d <- privateDependencies ds, Dependency p vr cs <- private_depends d])
DepMapUnion $
Map.fromListWith
unionVersionRanges'
( [((p, Public), (vr, cs)) | Dependency p vr cs <- publicDependencies ds]
++ [((p, Private (private_alias d)), (vr, cs)) | d <- privateDependencies ds, Dependency p vr cs <- private_depends d]
)

fromDepMapUnion :: DepMapUnion -> Dependencies
fromDepMapUnion m =
Dependencies
[Dependency p vr cs | ((p, Public), (vr, cs)) <- Map.toList (unDepMapUnion m)]
[PrivateDependency alias deps | (alias, deps) <- Map.toList priv_deps]
where
priv_deps = Map.fromListWith (++) [(sn, [Dependency p vr cs]) | ((p, Private sn), (vr, cs)) <- Map.toList (unDepMapUnion m)]
where
priv_deps = Map.fromListWith (++) [(sn, [Dependency p vr cs]) | ((p, Private sn), (vr, cs)) <- Map.toList (unDepMapUnion m)]

freeVars :: CondTree ConfVar c a -> [FlagName]
freeVars t = [f | PackageFlag f <- freeVars' t]
Expand Down Expand Up @@ -534,8 +537,10 @@ finalizePD
| otherwise -> [b, not b]
-- flagDefaults = map (\(n,x:_) -> (n,x)) flagChoices
check ds =
let missingDeps = Dependencies (filter (not . satisfyDep Nothing) (publicDependencies ds))
(mapMaybe (\(PrivateDependency priv pds) -> case filter (not . satisfyDep (Just priv)) pds of { [] -> Nothing; pds' -> Just (PrivateDependency priv pds') }) (privateDependencies ds))
let missingDeps =
Dependencies
(filter (not . satisfyDep Nothing) (publicDependencies ds))
(mapMaybe (\(PrivateDependency priv pds) -> case filter (not . satisfyDep (Just priv)) pds of [] -> Nothing; pds' -> Just (PrivateDependency priv pds')) (privateDependencies ds))
in if null (publicDependencies missingDeps) && null (privateDependencies missingDeps)
then DepOk
else MissingDeps missingDeps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ buildInfoFieldGrammar =
<*> pure mempty -- static-options ???
<*> prefixedFields "x-" L.customFieldsBI
<*> monoidalFieldAla "build-depends" formatDependencyList L.targetBuildDepends
<*> monoidalFieldAla "private-build-depends" formatPrivateDependencyList L.targetPrivateBuildDepends --(map (\(PrivateDependency a ds) -> (a, formatDependencyList ds))) (map (\(alias, ds) -> PrivateDependency alias (unpack' formatDependencyList ds))) L.targetPrivateBuildDepends
<*> monoidalFieldAla "private-build-depends" formatPrivateDependencyList L.targetPrivateBuildDepends -- (map (\(PrivateDependency a ds) -> (a, formatDependencyList ds))) (map (\(alias, ds) -> PrivateDependency alias (unpack' formatDependencyList ds))) L.targetPrivateBuildDepends
<*> monoidalFieldAla "mixins" formatMixinList L.mixins
^^^ availableSince CabalSpecV2_0 []
{-# SPECIALIZE buildInfoFieldGrammar :: ParsecFieldGrammar' BuildInfo #-}
Expand Down
4 changes: 2 additions & 2 deletions Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

-----------------------------------------------------------------------------

Expand Down Expand Up @@ -65,13 +65,13 @@ import qualified Data.Set as Set
import qualified Distribution.Compat.Newtype as Newtype
import qualified Distribution.Compat.NonEmptySet as NES
import qualified Distribution.Types.BuildInfo.Lens as L
import qualified Distribution.Types.Dependency.Lens as L
import qualified Distribution.Types.Executable.Lens as L
import qualified Distribution.Types.ForeignLib.Lens as L
import qualified Distribution.Types.GenericPackageDescription.Lens as L
import qualified Distribution.Types.PackageDescription.Lens as L
import qualified Distribution.Types.SetupBuildInfo.Lens as L
import qualified Text.Parsec as P
import qualified Distribution.Types.Dependency.Lens as L

------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ preProcessInternalDeps specVer gpd
transformD (Dependency pn vr ln)
| pn == thisPn =
if LMainLibName `NES.member` ln
then Dependency thisPn vr mainLibSet: sublibs
then Dependency thisPn vr mainLibSet : sublibs
else sublibs
where
sublibs =
Expand Down
3 changes: 1 addition & 2 deletions Cabal-syntax/src/Distribution/Types/ComponentName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module Distribution.Types.ComponentName
, componentNameRaw
, componentNameStanza
, componentNameString

, NotLibComponentName(..)
, NotLibComponentName (..)
) where

import Distribution.Compat.Prelude
Expand Down
23 changes: 11 additions & 12 deletions Cabal-syntax/src/Distribution/Types/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ module Distribution.Types.Dependency
, depLibraries
, simplifyDependency
, mainLibSet
, PrivateDependency(..)
, PrivateAlias(..)

, Dependencies(..)
, IsPrivate(..)
, PrivateDependency (..)
, PrivateAlias (..)
, Dependencies (..)
, IsPrivate (..)
, mapDependencies
) where

Expand All @@ -34,14 +33,14 @@ import Distribution.Types.LibraryName
import Distribution.Types.PackageName
import Distribution.Types.UnqualComponentName

import qualified Distribution.Compat.CharParsing as P
import qualified Distribution.Compat.NonEmptySet as NES
import qualified Text.PrettyPrint as PP
import Distribution.ModuleName
import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as PP

data IsPrivate = Private PrivateAlias | Public deriving (Show, Ord, Read, Eq)

data Dependencies = Dependencies { publicDependencies :: [Dependency], privateDependencies :: [PrivateDependency] } deriving (Eq, Show, Generic, Data)
data Dependencies = Dependencies {publicDependencies :: [Dependency], privateDependencies :: [PrivateDependency]} deriving (Eq, Show, Generic, Data)

newtype PrivateAlias = PrivateAlias ModuleName deriving (Show, Eq, Generic, Data, Read, Ord)

Expand All @@ -59,8 +58,7 @@ instance Parsec PrivateAlias where
instance IsString PrivateAlias where
fromString = PrivateAlias . fromString


data PrivateDependency = PrivateDependency { private_alias :: PrivateAlias, private_depends :: [Dependency] } deriving (Eq, Show, Generic, Data, Read, Ord)
data PrivateDependency = PrivateDependency {private_alias :: PrivateAlias, private_depends :: [Dependency]} deriving (Eq, Show, Generic, Data, Read, Ord)

instance Parsec PrivateDependency where
parsec = do
Expand All @@ -82,7 +80,7 @@ instance Monoid Dependencies where
mempty = Dependencies mempty mempty

mapDependencies :: (Dependency -> Dependency) -> Dependencies -> Dependencies
mapDependencies f (Dependencies pub priv) = Dependencies (map f pub) (map (\d -> d { private_depends = map f (private_depends d) }) priv)
mapDependencies f (Dependencies pub priv) = Dependencies (map f pub) (map (\d -> d{private_depends = map f (private_depends d)}) priv)

-- | Describes a dependency on a source package (API)
--
Expand Down Expand Up @@ -142,6 +140,7 @@ instance NFData PrivateAlias where rnf = genericRnf
instance Binary Dependencies
instance Structured Dependencies
instance NFData Dependencies where rnf = genericRnf

-- |
--
-- >>> prettyShow $ Dependency (mkPackageName "pkg") anyVersion mainLibSet
Expand Down Expand Up @@ -205,7 +204,7 @@ instance Pretty Dependency where
-- >>> map (`simpleParsec'` "mylib:sub") [CabalSpecV2_4, CabalSpecV3_0] :: [Maybe Dependency]
-- [Nothing,Just (Dependency (PackageName "mylib") (OrLaterVersion (mkVersion [0])) (fromNonEmpty (LSubLibName (UnqualComponentName "sub") :| [])))]
instance Parsec Dependency where
parsec :: forall m . CabalParsing m => m Dependency
parsec :: forall m. CabalParsing m => m Dependency
parsec = do
name <- parsec

Expand Down
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/Types/Dependency/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ import Distribution.Types.Dependency (Dependency, PrivateDependency)
import qualified Distribution.Types.Dependency as T

private_depends :: Lens' PrivateDependency [Dependency]
private_depends f d = fmap (\x -> d { T.private_depends = x}) (f (T.private_depends d))
private_depends f d = fmap (\x -> d{T.private_depends = x}) (f (T.private_depends d))
20 changes: 12 additions & 8 deletions Cabal-syntax/src/Distribution/Types/DependencyMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ intersectVersionRangesAndJoinComponents (va, ca) (vb, cb) =

toDepMap :: Dependencies -> DependencyMap
toDepMap ds =
DependencyMap $ Map.fromListWith intersectVersionRangesAndJoinComponents
( [((p, Public), (vr, cs)) | Dependency p vr cs <- publicDependencies ds]
++ [((p, Private pn), (vr, cs)) | PrivateDependency pn pds <- privateDependencies ds , Dependency p vr cs <- pds ] )
DependencyMap $
Map.fromListWith
intersectVersionRangesAndJoinComponents
( [((p, Public), (vr, cs)) | Dependency p vr cs <- publicDependencies ds]
++ [((p, Private pn), (vr, cs)) | PrivateDependency pn pds <- privateDependencies ds, Dependency p vr cs <- pds]
)

fromDepMap :: DependencyMap -> Dependencies
fromDepMap m = Dependencies
[Dependency p vr cs | ((p, Public), (vr, cs)) <- Map.toList (unDependencyMap m)]
[PrivateDependency alias deps | (alias, deps) <- Map.toList priv_deps]
where
priv_deps = Map.fromListWith (++) [(sn, [Dependency p vr cs]) | ((p, (Private sn)), (vr, cs)) <- Map.toList (unDependencyMap m)]
fromDepMap m =
Dependencies
[Dependency p vr cs | ((p, Public), (vr, cs)) <- Map.toList (unDependencyMap m)]
[PrivateDependency alias deps | (alias, deps) <- Map.toList priv_deps]
where
priv_deps = Map.fromListWith (++) [(sn, [Dependency p vr cs]) | ((p, (Private sn)), (vr, cs)) <- Map.toList (unDependencyMap m)]

-- Apply extra constraints to a dependency map.
-- Combines dependencies where the result will only contain keys from the left
Expand Down
8 changes: 4 additions & 4 deletions Cabal-syntax/src/Distribution/Types/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ enabledBuildInfos pkg enabled =
allBuildDepends :: PackageDescription -> [(Maybe PrivateAlias, Dependency)]
allBuildDepends pd = do
bi <- allBuildInfo pd
[(Nothing, d) | d <- targetBuildDepends bi ]
++ [(Just p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds ]
[(Nothing, d) | d <- targetBuildDepends bi]
++ [(Just p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds]

-- | Get the combined build-depends entries of all enabled components, per the
-- given request spec.
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [(Maybe PrivateAlias, Dependency)]
enabledBuildDepends spec pd =
do
bi <- enabledBuildInfos spec pd
[(Nothing, d) | d <- targetBuildDepends bi ]
++ [(Just p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds ]
[(Nothing, d) | d <- targetBuildDepends bi]
++ [(Just p, d) | PrivateDependency p ds <- targetPrivateBuildDepends bi, d <- ds]

updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription (mb_lib_bi, exe_bi) p =
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Backpack/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ configureComponentLocalBuildInfos
`Map.union` Map.fromListWith
Map.union
[ ( (pkg, alias)
, Map.singleton (ann_cname aid) aid)
, Map.singleton (ann_cname aid) aid
)
| PromisedComponent pkg aid alias <- promisedPkgDeps
]
graph1 <-
Expand Down
14 changes: 8 additions & 6 deletions Cabal/src/Distribution/Backpack/ConfiguredComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ mkConfiguredComponent pkg_descr this_cid lib_deps exe_deps component = do
{ ci_ann_id = aid
, ci_renaming = rns
, ci_implicit = False
-- Mixins can't be private
, ci_alias = Nothing
, -- Mixins can't be private
ci_alias = Nothing
}

-- Any @build-depends@ which is not explicitly mentioned in
-- @backpack-include@ is converted into an "implicit" include.
let used_explicitly = Set.fromList (map ci_id explicit_includes)
implicit_includes =
map
( \(aid, alias)->
( \(aid, alias) ->
ComponentInclude
{ ci_ann_id = aid
, ci_renaming = defaultIncludeRenaming
Expand Down Expand Up @@ -184,14 +184,15 @@ toConfiguredComponent pkg_descr this_cid lib_dep_map exe_dep_map component = do
lib_deps <-
if newPackageDepsBehaviour pkg_descr
then fmap concat $
forM ([ (d, Nothing) | d <- targetBuildDepends bi] ++ [ (d, Just alias) | (PrivateDependency alias ds) <- targetPrivateBuildDepends bi, d <- ds]) $
forM ([(d, Nothing) | d <- targetBuildDepends bi] ++ [(d, Just alias) | (PrivateDependency alias ds) <- targetPrivateBuildDepends bi, d <- ds]) $
\((Dependency name _ sublibs), alias) -> do
case Map.lookup (name, alias) lib_dep_map of
Nothing ->
dieProgress $
text "Dependency on unbuildable"
<+> text "package"
<+> pretty name <+> maybe mempty pretty alias
<+> pretty name
<+> maybe mempty pretty alias
<+> text (show lib_dep_map)
Just pkg -> do
-- Return all library components
Expand All @@ -203,7 +204,8 @@ toConfiguredComponent pkg_descr this_cid lib_dep_map exe_dep_map component = do
text "Dependency on unbuildable"
<+> text (showLibraryName lib)
<+> text "from"
<+> pretty name <+> maybe mempty pretty alias
<+> pretty name
<+> maybe mempty pretty alias
Just v -> return (v, alias)
else return old_style_lib_deps
mkConfiguredComponent
Expand Down
3 changes: 1 addition & 2 deletions Cabal/src/Distribution/Backpack/LinkedComponent.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE BangPatterns #-}

-- | See <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
module Distribution.Backpack.LinkedComponent
Expand Down Expand Up @@ -151,7 +151,6 @@ toLinkedComponent
_ -> ([], [], [])
src_hidden = otherModules (componentBuildInfo component)


-- HERE??
-- Take each included ComponentId and resolve it into an
-- \*unlinked* unit identity. We will use unification (relying
Expand Down
5 changes: 3 additions & 2 deletions Cabal/src/Distribution/Backpack/ModuleScope.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import Text.PrettyPrint
data ModuleScope = ModuleScope
{ modScopeProvides :: ModuleProvides
, modScopeRequires :: ModuleRequires
} deriving Show
}
deriving (Show)

-- | An empty 'ModuleScope'.
emptyModuleScope :: ModuleScope
Expand All @@ -92,7 +93,7 @@ data ModuleSource
| FromExposedModules ModuleName
| FromOtherModules ModuleName
| FromSignatures ModuleName
deriving Show
deriving (Show)

-- We don't have line numbers, but if we did, we'd want to record that
-- too
Expand Down
24 changes: 9 additions & 15 deletions Cabal/src/Distribution/Backpack/UnifyM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -625,25 +625,19 @@ convertInclude

-- Expand the alias
let prepend_alias mn = case alias of
Just (PrivateAlias alias_mn) -> fromComponents (components alias_mn ++ components mn)
Nothing -> mn

Just (PrivateAlias alias_mn) -> fromComponents (components alias_mn ++ components mn)
Nothing -> mn

let pre_prov_scope' = map (first prepend_alias) pre_prov_scope

let prov_rns'' =
case prov_rns' of
DefaultRenaming -> case alias of
Nothing -> DefaultRenaming
Just {} -> ModuleRenaming (map ((\x -> (x, prepend_alias x)) . fst) (pre_prov_scope))


ModuleRenaming rn -> ModuleRenaming (map (\(x, y) -> (x, prepend_alias y)) rn)
-- Can't happen, expanded avove
HidingRenaming {} -> error "unreachabel"



case prov_rns' of
DefaultRenaming -> case alias of
Nothing -> DefaultRenaming
Just{} -> ModuleRenaming (map ((\x -> (x, prepend_alias x)) . fst) (pre_prov_scope))
ModuleRenaming rn -> ModuleRenaming (map (\(x, y) -> (x, prepend_alias y)) rn)
-- Can't happen, expanded avove
HidingRenaming{} -> error "unreachabel"

let prov_scope =
modSubst req_subst $
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ combinedConstraints constraints dependencies installedPackages = do
-- NB: do NOT use the packageName from
-- dependenciesPkgInfo!
[ ((pn, cname, alias), pkg)
| (pn, cname, alias, _, Just pkg) <- dependenciesPkgInfo
| (pn, cname, alias, _, Just pkg) <- dependenciesPkgInfo
]

-- The dependencies along with the installed package info, if it exists
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Distribution.Simple.Setup
, ConfigFlags (..)
, emptyConfigFlags
, defaultConfigFlags
, AliasDependency(..)
, AliasDependency (..)
, configureCommand
, configPrograms
, configAbsolutePaths
Expand Down
Loading

0 comments on commit 6c19b98

Please sign in to comment.