Skip to content

Commit 2b44384

Browse files
committed
Make cabal-install compilable with NoImplicitPrelude
I.e. find out where we don't yet used `Distribution.Client.Compat.Prelude`. - If the module is small I added direct `Prelude` imports. - Add Exception, deepseq stuff to Cabal Prelude - Add Parsec, Pretty and Verbosity to Client Prelude - use for, for_, traverse and traverse_ (removes need for Control.Monad)
1 parent a4f2082 commit 2b44384

File tree

199 files changed

+714
-846
lines changed

Some content is hidden

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

199 files changed

+714
-846
lines changed

Cabal/Distribution/Backpack/LinkedComponent.hs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@ import Distribution.Utils.LogProgress
4343

4444
import qualified Data.Set as Set
4545
import qualified Data.Map as Map
46-
import Data.Traversable
47-
( mapM )
4846
import Distribution.Pretty (pretty)
49-
import Text.PrettyPrint
50-
import Data.Either
47+
import Text.PrettyPrint (Doc, hang, text, vcat, ($+$), hsep, quotes)
5148

5249
-- | A linked component is a component that has been mix-in linked, at
5350
-- which point we have determined how all the dependencies of the
@@ -187,19 +184,19 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent {
187184
m_u <- convertModule (OpenModule this_uid m)
188185
return (Map.singleton m [WithSource (from m) m_u], Map.empty)
189186
-- Handle 'exposed-modules'
190-
exposed_mod_shapes_u <- mapM (convertMod FromExposedModules) src_provs
187+
exposed_mod_shapes_u <- traverse (convertMod FromExposedModules) src_provs
191188
-- Handle 'other-modules'
192-
other_mod_shapes_u <- mapM (convertMod FromOtherModules) src_hidden
189+
other_mod_shapes_u <- traverse (convertMod FromOtherModules) src_hidden
193190

194191
-- Handle 'signatures'
195192
let convertReq :: ModuleName -> UnifyM s (ModuleScopeU s)
196193
convertReq req = do
197194
req_u <- convertModule (OpenModuleVar req)
198195
return (Map.empty, Map.singleton req [WithSource (FromSignatures req) req_u])
199-
req_shapes_u <- mapM convertReq src_reqs
196+
req_shapes_u <- traverse convertReq src_reqs
200197

201198
-- Handle 'mixins'
202-
(incl_shapes_u, all_includes_u) <- fmap unzip (mapM convertInclude unlinked_includes)
199+
(incl_shapes_u, all_includes_u) <- fmap unzip (traverse convertInclude unlinked_includes)
203200

204201
failIfErrs -- Prevent error cascade
205202
-- Mix-in link everything! mixLink is the real workhorse.
@@ -208,7 +205,7 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent {
208205
++ req_shapes_u
209206
++ incl_shapes_u
210207

211-
-- src_reqs_u <- mapM convertReq src_reqs
208+
-- src_reqs_u <- traverse convertReq src_reqs
212209
-- Read out all the final results by converting back
213210
-- into a pure representation.
214211
let convertIncludeU (ComponentInclude dep_aid rns i) = do
@@ -220,8 +217,8 @@ toLinkedComponent verbosity db this_pid pkg_map ConfiguredComponent {
220217
})
221218
shape <- convertModuleScopeU shape_u
222219
let (includes_u, sig_includes_u) = partitionEithers all_includes_u
223-
incls <- mapM convertIncludeU includes_u
224-
sig_incls <- mapM convertIncludeU sig_includes_u
220+
incls <- traverse convertIncludeU includes_u
221+
sig_incls <- traverse convertIncludeU sig_includes_u
225222
return (shape, incls, sig_incls)
226223

227224
let isNotLib (CLib _) = False

Cabal/Distribution/Backpack/ReadyComponent.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ import Distribution.ModuleName
3939
import Distribution.Package
4040
import Distribution.Simple.Utils
4141

42-
import qualified Control.Applicative as A
43-
import qualified Data.Traversable as T
44-
4542
import Control.Monad
4643
import Text.PrettyPrint
4744
import qualified Data.Map as Map
@@ -198,14 +195,14 @@ instance Functor InstM where
198195
fmap f (InstM m) = InstM $ \s -> let (x, s') = m s
199196
in (f x, s')
200197

201-
instance A.Applicative InstM where
198+
instance Applicative InstM where
202199
pure a = InstM $ \s -> (a, s)
203200
InstM f <*> InstM x = InstM $ \s -> let (f', s') = f s
204201
(x', s'') = x s'
205202
in (f' x', s'')
206203

207204
instance Monad InstM where
208-
return = A.pure
205+
return = pure
209206
InstM m >>= f = InstM $ \s -> let (x, s') = m s
210207
in runInstM (f x) s'
211208

@@ -259,20 +256,20 @@ toReadyComponents pid_map subst0 comps
259256
-> InstM (Maybe ReadyComponent)
260257
instantiateComponent uid cid insts
261258
| Just lc <- Map.lookup cid cmap = do
262-
provides <- T.mapM (substModule insts) (modShapeProvides (lc_shape lc))
259+
provides <- traverse (substModule insts) (modShapeProvides (lc_shape lc))
263260
-- NB: lc_sig_includes is omitted here, because we don't
264261
-- need them to build
265262
includes <- forM (lc_includes lc) $ \ci -> do
266263
uid' <- substUnitId insts (ci_id ci)
267264
return ci { ci_ann_id = fmap (const uid') (ci_ann_id ci) }
268-
exe_deps <- mapM (substExeDep insts) (lc_exe_deps lc)
265+
exe_deps <- traverse (substExeDep insts) (lc_exe_deps lc)
269266
s <- InstM $ \s -> (s, s)
270267
let getDep (Module dep_def_uid _)
271268
| let dep_uid = unDefUnitId dep_def_uid
272269
-- Lose DefUnitId invariant for rc_depends
273270
= [(dep_uid,
274271
fromMaybe err_pid $
275-
Map.lookup dep_uid pid_map A.<|>
272+
Map.lookup dep_uid pid_map <|>
276273
fmap rc_munged_id (join (Map.lookup dep_uid s)))]
277274
where
278275
err_pid = MungedPackageId
@@ -313,7 +310,7 @@ toReadyComponents pid_map subst0 comps
313310
substSubst :: Map ModuleName Module
314311
-> Map ModuleName OpenModule
315312
-> InstM (Map ModuleName Module)
316-
substSubst subst insts = T.mapM (substModule subst) insts
313+
substSubst subst insts = traverse (substModule subst) insts
317314

318315
substModule :: Map ModuleName Module -> OpenModule -> InstM Module
319316
substModule subst (OpenModuleVar mod_name)
@@ -346,7 +343,7 @@ toReadyComponents pid_map subst0 comps
346343
then do uid' <- substUnitId Map.empty (ci_id ci)
347344
return $ ci { ci_ann_id = fmap (const (DefiniteUnitId uid')) (ci_ann_id ci) }
348345
else return ci
349-
exe_deps <- mapM (substExeDep Map.empty) (lc_exe_deps lc)
346+
exe_deps <- traverse (substExeDep Map.empty) (lc_exe_deps lc)
350347
let indefc = IndefiniteComponent {
351348
indefc_requires = map fst (lc_insts lc),
352349
indefc_provides = modShapeProvides (lc_shape lc),

Cabal/Distribution/Backpack/UnifyM.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import qualified Data.Map as Map
7070
import qualified Data.Set as Set
7171
import Data.IntMap (IntMap)
7272
import qualified Data.IntMap as IntMap
73-
import qualified Data.Traversable as T
7473
import Text.PrettyPrint
7574

7675
-- TODO: more detailed trace output on high verbosity would probably
@@ -321,7 +320,7 @@ convertUnitId' _ (DefiniteUnitId uid) =
321320
convertUnitId' stk (IndefFullUnitId cid insts) = do
322321
fs <- fmap unify_uniq getUnifEnv
323322
x <- liftST $ UnionFind.fresh (error "convertUnitId") -- tie the knot later
324-
insts_u <- T.forM insts $ convertModule' (extendMuEnv stk x)
323+
insts_u <- for insts $ convertModule' (extendMuEnv stk x)
325324
u <- readUnifRef fs
326325
writeUnifRef fs (u+1)
327326
y <- liftST $ UnionFind.fresh (UnitIdU u cid insts_u)
@@ -359,11 +358,11 @@ type ModuleSubstU s = Map ModuleName (ModuleU s)
359358

360359
-- | Conversion of 'ModuleSubst' to 'ModuleSubstU'
361360
convertModuleSubst :: Map ModuleName OpenModule -> UnifyM s (Map ModuleName (ModuleU s))
362-
convertModuleSubst = T.mapM convertModule
361+
convertModuleSubst = traverse convertModule
363362

364363
-- | Conversion of 'ModuleSubstU' to 'ModuleSubst'
365364
convertModuleSubstU :: ModuleSubstU s -> UnifyM s OpenModuleSubst
366-
convertModuleSubstU = T.mapM convertModuleU
365+
convertModuleSubstU = traverse convertModuleU
367366

368367
-----------------------------------------------------------------------
369368
-- Conversion from the unifiable data types
@@ -400,7 +399,7 @@ convertUnitIdU' stk uid_u = do
400399
failWith (text "Unsupported mutually recursive unit identifier")
401400
-- return (UnitIdVar i)
402401
Nothing -> do
403-
insts <- T.forM insts_u $ convertModuleU' (extendMooEnv stk u)
402+
insts <- for insts_u $ convertModuleU' (extendMooEnv stk u)
404403
return (IndefFullUnitId cid insts)
405404

406405
convertModuleU' :: MooEnv -> ModuleU s -> UnifyM s OpenModule
@@ -615,11 +614,11 @@ convertModuleScopeU (provs_u, reqs_u) = do
615614

616615
-- | Convert a 'ModuleProvides' to a 'ModuleProvidesU'
617616
convertModuleProvides :: ModuleProvides -> UnifyM s (ModuleProvidesU s)
618-
convertModuleProvides = T.mapM (mapM (T.mapM convertModule))
617+
convertModuleProvides = traverse (traverse (traverse convertModule))
619618

620619
-- | Convert a 'ModuleProvidesU' to a 'ModuleProvides'
621620
convertModuleProvidesU :: ModuleProvidesU s -> UnifyM s ModuleProvides
622-
convertModuleProvidesU = T.mapM (mapM (T.mapM convertModuleU))
621+
convertModuleProvidesU = traverse (traverse (traverse convertModuleU))
623622

624623
convertModuleRequires :: ModuleRequires -> UnifyM s (ModuleRequiresU s)
625624
convertModuleRequires = convertModuleProvides

Cabal/Distribution/Compat/CopyFile.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ module Distribution.Compat.CopyFile (
1414
import Prelude ()
1515
import Distribution.Compat.Prelude
1616

17-
import Distribution.Compat.Exception
18-
1917
#ifndef mingw32_HOST_OS
2018
import Distribution.Compat.Internal.TempFile
2119

2220
import Control.Exception
23-
( bracketOnError, throwIO )
21+
( bracketOnError )
2422
import qualified Data.ByteString.Lazy as BSL
2523
import System.IO.Error
2624
( ioeSetLocation )
@@ -43,8 +41,6 @@ import Foreign.C
4341

4442
#else /* else mingw32_HOST_OS */
4543

46-
import Control.Exception
47-
( throwIO )
4844
import qualified Data.ByteString.Lazy as BSL
4945
import System.IO.Error
5046
( ioeSetLocation )

Cabal/Distribution/Compat/Exception.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,32 @@ module Distribution.Compat.Exception (
66
displayException,
77
) where
88

9+
#ifdef MIN_VERSION_base
10+
#define MINVER_base_48 MIN_VERSION_base(4,8,0)
11+
#else
12+
#define MINVER_base_48 (__GLASGOW_HASKELL__ >= 710)
13+
#endif
14+
915
import System.Exit
1016
import qualified Control.Exception as Exception
11-
#if __GLASGOW_HASKELL__ >= 710
17+
18+
#if MINVER_base_48
1219
import Control.Exception (displayException)
1320
#endif
1421

22+
-- | Try 'IOException'.
1523
tryIO :: IO a -> IO (Either Exception.IOException a)
1624
tryIO = Exception.try
1725

26+
-- | Catch 'IOException'.
1827
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
1928
catchIO = Exception.catch
2029

30+
-- | Catch 'ExitCode'
2131
catchExit :: IO a -> (ExitCode -> IO a) -> IO a
2232
catchExit = Exception.catch
2333

24-
#if __GLASGOW_HASKELL__ < 710
34+
#if !MINVER_base_48
2535
displayException :: Exception.Exception e => e -> String
2636
displayException = show
2737
#endif

Cabal/Distribution/Compat/Graph.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ import Distribution.Compat.Prelude hiding (empty, lookup, null, toList)
8888
import Prelude ()
8989

9090
import Data.Array ((!))
91-
import Data.Either (partitionEithers)
9291
import Data.Graph (SCC (..))
9392
import Distribution.Utils.Structured (Structure (..), Structured (..))
9493

Cabal/Distribution/Compat/Lens.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module Distribution.Compat.Lens (
5050
import Prelude()
5151
import Distribution.Compat.Prelude
5252

53-
import Control.Applicative (Const (..))
5453
import Control.Monad.State.Class (MonadState (..), gets, modify)
5554

5655
import qualified Distribution.Compat.DList as DList

0 commit comments

Comments
 (0)