Skip to content

Commit 10a1439

Browse files
committed
Format the codebase with Fourmolu
1 parent bd252d2 commit 10a1439

File tree

444 files changed

+84401
-68646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+84401
-68646
lines changed

Cabal-syntax/Setup.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import Distribution.Simple
2+
23
main :: IO ()
34
main = defaultMain
Lines changed: 95 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
{-# LANGUAGE DeriveDataTypeable #-}
2-
{-# LANGUAGE DeriveGeneric #-}
3-
{-# LANGUAGE FlexibleInstances #-}
1+
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE FlexibleInstances #-}
44
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5-
{-# LANGUAGE PatternGuards #-}
6-
{-# LANGUAGE RankNTypes #-}
5+
{-# LANGUAGE PatternGuards #-}
6+
{-# LANGUAGE RankNTypes #-}
77

88
-- | This module defines the core data types for Backpack. For more
99
-- details, see:
1010
--
1111
-- <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
12-
13-
module Distribution.Backpack (
14-
-- * OpenUnitId
15-
OpenUnitId(..),
16-
openUnitIdFreeHoles,
17-
mkOpenUnitId,
12+
module Distribution.Backpack
13+
( -- * OpenUnitId
14+
OpenUnitId (..)
15+
, openUnitIdFreeHoles
16+
, mkOpenUnitId
1817

1918
-- * DefUnitId
20-
DefUnitId,
21-
unDefUnitId,
22-
mkDefUnitId,
19+
, DefUnitId
20+
, unDefUnitId
21+
, mkDefUnitId
2322

2423
-- * OpenModule
25-
OpenModule(..),
26-
openModuleFreeHoles,
24+
, OpenModule (..)
25+
, openModuleFreeHoles
2726

2827
-- * OpenModuleSubst
29-
OpenModuleSubst,
30-
dispOpenModuleSubst,
31-
dispOpenModuleSubstEntry,
32-
parsecOpenModuleSubst,
33-
parsecOpenModuleSubstEntry,
34-
openModuleSubstFreeHoles,
28+
, OpenModuleSubst
29+
, dispOpenModuleSubst
30+
, dispOpenModuleSubstEntry
31+
, parsecOpenModuleSubst
32+
, parsecOpenModuleSubstEntry
33+
, openModuleSubstFreeHoles
3534

3635
-- * Conversions to 'UnitId'
37-
abstractUnitId,
38-
hashModuleSubst,
39-
) where
36+
, abstractUnitId
37+
, hashModuleSubst
38+
) where
4039

4140
import Distribution.Compat.Prelude hiding (mod)
4241
import Distribution.Parsec
4342
import Distribution.Pretty
43+
import Text.PrettyPrint (hcat)
4444
import Prelude ()
45-
import Text.PrettyPrint (hcat)
4645

4746
import qualified Distribution.Compat.CharParsing as P
48-
import qualified Text.PrettyPrint as Disp
47+
import qualified Text.PrettyPrint as Disp
4948

5049
import Distribution.ModuleName
5150
import Distribution.Types.ComponentId
@@ -81,52 +80,53 @@ import qualified Data.Set as Set
8180
--
8281
-- For more details see the Backpack spec
8382
-- <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
84-
--
85-
8683
data OpenUnitId
87-
-- | Identifies a component which may have some unfilled holes;
84+
= -- | Identifies a component which may have some unfilled holes;
8885
-- specifying its 'ComponentId' and its 'OpenModuleSubst'.
8986
-- TODO: Invariant that 'OpenModuleSubst' is non-empty?
9087
-- See also the Text instance.
91-
= IndefFullUnitId ComponentId OpenModuleSubst
92-
-- | Identifies a fully instantiated component, which has
88+
IndefFullUnitId ComponentId OpenModuleSubst
89+
| -- | Identifies a fully instantiated component, which has
9390
-- been compiled and abbreviated as a hash. The embedded 'UnitId'
9491
-- MUST NOT be for an indefinite component; an 'OpenUnitId'
9592
-- is guaranteed not to have any holes.
96-
| DefiniteUnitId DefUnitId
93+
DefiniteUnitId DefUnitId
9794
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
95+
9896
-- TODO: cache holes?
9997

10098
instance Binary OpenUnitId
10199
instance Structured OpenUnitId
102100
instance NFData OpenUnitId where
103-
rnf (IndefFullUnitId cid subst) = rnf cid `seq` rnf subst
104-
rnf (DefiniteUnitId uid) = rnf uid
101+
rnf (IndefFullUnitId cid subst) = rnf cid `seq` rnf subst
102+
rnf (DefiniteUnitId uid) = rnf uid
105103

106104
instance Pretty OpenUnitId where
107-
pretty (IndefFullUnitId cid insts)
108-
-- TODO: arguably a smart constructor to enforce invariant would be
109-
-- better
110-
| Map.null insts = pretty cid
111-
| otherwise = pretty cid <<>> Disp.brackets (dispOpenModuleSubst insts)
112-
pretty (DefiniteUnitId uid) = pretty uid
105+
pretty (IndefFullUnitId cid insts)
106+
-- TODO: arguably a smart constructor to enforce invariant would be
107+
-- better
108+
| Map.null insts = pretty cid
109+
| otherwise = pretty cid <<>> Disp.brackets (dispOpenModuleSubst insts)
110+
pretty (DefiniteUnitId uid) = pretty uid
113111

114112
-- |
115113
--
116114
-- >>> eitherParsec "foobar" :: Either String OpenUnitId
117-
--Right (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "foobar"}))
115+
-- Right (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "foobar"}))
118116
--
119117
-- >>> eitherParsec "foo[Str=text-1.2.3:Data.Text.Text]" :: Either String OpenUnitId
120118
-- Right (IndefFullUnitId (ComponentId "foo") (fromList [(ModuleName "Str",OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "text-1.2.3"})) (ModuleName "Data.Text.Text"))]))
121-
--
122119
instance Parsec OpenUnitId where
123-
parsec = P.try parseOpenUnitId <|> fmap DefiniteUnitId parsec
124-
where
125-
parseOpenUnitId = do
126-
cid <- parsec
127-
insts <- P.between (P.char '[') (P.char ']')
128-
parsecOpenModuleSubst
129-
return (IndefFullUnitId cid insts)
120+
parsec = P.try parseOpenUnitId <|> fmap DefiniteUnitId parsec
121+
where
122+
parseOpenUnitId = do
123+
cid <- parsec
124+
insts <-
125+
P.between
126+
(P.char '[')
127+
(P.char ']')
128+
parsecOpenModuleSubst
129+
return (IndefFullUnitId cid insts)
130130

131131
-- | Get the set of holes ('ModuleVar') embedded in a 'UnitId'.
132132
openUnitIdFreeHoles :: OpenUnitId -> Set ModuleName
@@ -137,9 +137,9 @@ openUnitIdFreeHoles _ = Set.empty
137137
-- is if the instantiation is provided.
138138
mkOpenUnitId :: UnitId -> ComponentId -> OpenModuleSubst -> OpenUnitId
139139
mkOpenUnitId uid cid insts =
140-
if Set.null (openModuleSubstFreeHoles insts)
141-
then DefiniteUnitId (unsafeMkDefUnitId uid) -- invariant holds!
142-
else IndefFullUnitId cid insts
140+
if Set.null (openModuleSubstFreeHoles insts)
141+
then DefiniteUnitId (unsafeMkDefUnitId uid) -- invariant holds!
142+
else IndefFullUnitId cid insts
143143

144144
-----------------------------------------------------------------------
145145
-- DefUnitId
@@ -148,9 +148,12 @@ mkOpenUnitId uid cid insts =
148148
-- with no holes.
149149
mkDefUnitId :: ComponentId -> Map ModuleName Module -> DefUnitId
150150
mkDefUnitId cid insts =
151-
unsafeMkDefUnitId (mkUnitId
152-
(unComponentId cid ++ maybe "" ("+"++) (hashModuleSubst insts)))
153-
-- impose invariant!
151+
unsafeMkDefUnitId
152+
( mkUnitId
153+
(unComponentId cid ++ maybe "" ("+" ++) (hashModuleSubst insts))
154+
)
155+
156+
-- impose invariant!
154157

155158
-----------------------------------------------------------------------
156159
-- OpenModule
@@ -160,42 +163,41 @@ mkDefUnitId cid insts =
160163
-- hole that needs to be filled in. Substitutions are over
161164
-- module variables.
162165
data OpenModule
163-
= OpenModule OpenUnitId ModuleName
164-
| OpenModuleVar ModuleName
166+
= OpenModule OpenUnitId ModuleName
167+
| OpenModuleVar ModuleName
165168
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
166169

167170
instance Binary OpenModule
168171
instance Structured OpenModule
169172

170173
instance NFData OpenModule where
171-
rnf (OpenModule uid mod_name) = rnf uid `seq` rnf mod_name
172-
rnf (OpenModuleVar mod_name) = rnf mod_name
174+
rnf (OpenModule uid mod_name) = rnf uid `seq` rnf mod_name
175+
rnf (OpenModuleVar mod_name) = rnf mod_name
173176

174177
instance Pretty OpenModule where
175-
pretty (OpenModule uid mod_name) =
176-
hcat [pretty uid, Disp.text ":", pretty mod_name]
177-
pretty (OpenModuleVar mod_name) =
178-
hcat [Disp.char '<', pretty mod_name, Disp.char '>']
178+
pretty (OpenModule uid mod_name) =
179+
hcat [pretty uid, Disp.text ":", pretty mod_name]
180+
pretty (OpenModuleVar mod_name) =
181+
hcat [Disp.char '<', pretty mod_name, Disp.char '>']
179182

180183
-- |
181184
--
182185
-- >>> eitherParsec "Includes2-0.1.0.0-inplace-mysql:Database.MySQL" :: Either String OpenModule
183186
-- Right (OpenModule (DefiniteUnitId (DefUnitId {unDefUnitId = UnitId "Includes2-0.1.0.0-inplace-mysql"})) (ModuleName "Database.MySQL"))
184-
--
185187
instance Parsec OpenModule where
186-
parsec = parsecModuleVar <|> parsecOpenModule
187-
where
188-
parsecOpenModule = do
189-
uid <- parsec
190-
_ <- P.char ':'
191-
mod_name <- parsec
192-
return (OpenModule uid mod_name)
193-
194-
parsecModuleVar = do
195-
_ <- P.char '<'
196-
mod_name <- parsec
197-
_ <- P.char '>'
198-
return (OpenModuleVar mod_name)
188+
parsec = parsecModuleVar <|> parsecOpenModule
189+
where
190+
parsecOpenModule = do
191+
uid <- parsec
192+
_ <- P.char ':'
193+
mod_name <- parsec
194+
return (OpenModule uid mod_name)
195+
196+
parsecModuleVar = do
197+
_ <- P.char '<'
198+
mod_name <- parsec
199+
_ <- P.char '>'
200+
return (OpenModuleVar mod_name)
199201

200202
-- | Get the set of holes ('ModuleVar') embedded in a 'Module'.
201203
openModuleFreeHoles :: OpenModule -> Set ModuleName
@@ -214,8 +216,8 @@ type OpenModuleSubst = Map ModuleName OpenModule
214216
-- | Pretty-print the entries of a module substitution, suitable
215217
-- for embedding into a 'OpenUnitId' or passing to GHC via @--instantiate-with@.
216218
dispOpenModuleSubst :: OpenModuleSubst -> Disp.Doc
217-
dispOpenModuleSubst subst
218-
= Disp.hcat
219+
dispOpenModuleSubst subst =
220+
Disp.hcat
219221
. Disp.punctuate Disp.comma
220222
$ map dispOpenModuleSubstEntry (Map.toAscList subst)
221223

@@ -227,19 +229,21 @@ dispOpenModuleSubstEntry (k, v) = pretty k <<>> Disp.char '=' <<>> pretty v
227229
--
228230
-- @since 2.2
229231
parsecOpenModuleSubst :: CabalParsing m => m OpenModuleSubst
230-
parsecOpenModuleSubst = fmap Map.fromList
231-
. flip P.sepBy (P.char ',')
232-
$ parsecOpenModuleSubstEntry
232+
parsecOpenModuleSubst =
233+
fmap Map.fromList
234+
. flip P.sepBy (P.char ',')
235+
$ parsecOpenModuleSubstEntry
233236

234237
-- | Inverse to 'dispModSubstEntry'.
235238
--
236239
-- @since 2.2
237240
parsecOpenModuleSubstEntry :: CabalParsing m => m (ModuleName, OpenModule)
238241
parsecOpenModuleSubstEntry =
239-
do k <- parsec
240-
_ <- P.char '='
241-
v <- parsec
242-
return (k, v)
242+
do
243+
k <- parsec
244+
_ <- P.char '='
245+
v <- parsec
246+
return (k, v)
243247

244248
-- | Get the set of holes ('ModuleVar') embedded in a 'OpenModuleSubst'.
245249
-- This is NOT the domain of the substitution.
@@ -265,5 +269,7 @@ hashModuleSubst subst
265269
| Map.null subst = Nothing
266270
| otherwise =
267271
Just . hashToBase62 $
268-
concat [ prettyShow mod_name ++ "=" ++ prettyShow m ++ "\n"
269-
| (mod_name, m) <- Map.toList subst]
272+
concat
273+
[ prettyShow mod_name ++ "=" ++ prettyShow m ++ "\n"
274+
| (mod_name, m) <- Map.toList subst
275+
]

0 commit comments

Comments
 (0)