Module.hs 18 KB
Newer Older
Austin Seipp's avatar
Austin Seipp committed
1 2 3
{-
(c) The University of Glasgow, 2004-2006

sof's avatar
sof committed
4

5
Module
6
~~~~~~~~~~
7
Simply the name of a module, represented as a FastString.
8
These are Uniquable, hence we can build Maps with Modules as
9
the keys.
Austin Seipp's avatar
Austin Seipp committed
10
-}
sof's avatar
sof committed
11

12
{-# LANGUAGE DeriveDataTypeable #-}
dterei's avatar
dterei committed
13 14

module Module
sof's avatar
sof committed
15
    (
16 17 18 19 20 21 22 23 24
        -- * The ModuleName type
        ModuleName,
        pprModuleName,
        moduleNameFS,
        moduleNameString,
        moduleNameSlashes, moduleNameColons,
        mkModuleName,
        mkModuleNameFS,
        stableModuleNameCmp,
Simon Marlow's avatar
Simon Marlow committed
25

26 27 28 29 30 31 32 33 34
        -- * The PackageKey type
        PackageKey,
        fsToPackageKey,
        packageKeyFS,
        stringToPackageKey,
        packageKeyString,
        stablePackageKeyCmp,

        -- * Wired-in PackageKeys
dterei's avatar
dterei committed
35
        -- $wired_in_packages
36 37 38 39 40 41 42 43 44
        primPackageKey,
        integerPackageKey,
        basePackageKey,
        rtsPackageKey,
        thPackageKey,
        dphSeqPackageKey,
        dphParPackageKey,
        mainPackageKey,
        thisGhcPackageKey,
45
        holePackageKey, isHoleModule,
46
        interactivePackageKey, isInteractiveModule,
47
        wiredInPackageKeys,
dterei's avatar
dterei committed
48 49

        -- * The Module type
Joel Burget's avatar
Joel Burget committed
50
        Module(Module),
51
        modulePackageKey, moduleName,
dterei's avatar
dterei committed
52 53
        pprModule,
        mkModule,
54
        stableModuleCmp,
55 56
        HasModule(..),
        ContainsModule(..),
Simon Marlow's avatar
Simon Marlow committed
57

dterei's avatar
dterei committed
58 59 60 61 62 63 64 65 66 67 68
        -- * The ModuleLocation type
        ModLocation(..),
        addBootSuffix, addBootSuffix_maybe, addBootSuffixLocn,

        -- * Module mappings
        ModuleEnv,
        elemModuleEnv, extendModuleEnv, extendModuleEnvList,
        extendModuleEnvList_C, plusModuleEnv_C,
        delModuleEnvList, delModuleEnv, plusModuleEnv, lookupModuleEnv,
        lookupWithDefaultModuleEnv, mapModuleEnv, mkModuleEnv, emptyModuleEnv,
        moduleEnvKeys, moduleEnvElts, moduleEnvToList,
69
        unitModuleEnv, isEmptyModuleEnv,
70
        foldModuleEnv, extendModuleEnvWith, filterModuleEnv,
Simon Marlow's avatar
Simon Marlow committed
71

dterei's avatar
dterei committed
72 73
        -- * ModuleName mappings
        ModuleNameEnv,
Simon Marlow's avatar
Simon Marlow committed
74

dterei's avatar
dterei committed
75
        -- * Sets of Modules
Austin Seipp's avatar
Austin Seipp committed
76
        ModuleSet,
dterei's avatar
dterei committed
77
        emptyModuleSet, mkModuleSet, moduleSetElts, extendModuleSet, elemModuleSet
sof's avatar
sof committed
78 79
    ) where

80
import Config
sof's avatar
sof committed
81
import Outputable
Simon Marlow's avatar
Simon Marlow committed
82
import Unique
83
import UniqFM
84
import FastString
Simon Marlow's avatar
Simon Marlow committed
85
import Binary
86
import Util
87
import {-# SOURCE #-} Packages
88
import GHC.PackageDb (BinaryStringRep(..))
89

90
import Data.Data
91 92 93
import Data.Map (Map)
import qualified Data.Map as Map
import qualified FiniteMap as Map
94
import System.FilePath
sof's avatar
sof committed
95

Austin Seipp's avatar
Austin Seipp committed
96 97 98
{-
************************************************************************
*                                                                      *
99
\subsection{Module locations}
Austin Seipp's avatar
Austin Seipp committed
100 101 102
*                                                                      *
************************************************************************
-}
sof's avatar
sof committed
103

batterseapower's avatar
batterseapower committed
104 105
-- | Where a module lives on the file system: the actual locations
-- of the .hs, .hi and .o files, if we have them
106 107 108
data ModLocation
   = ModLocation {
        ml_hs_file   :: Maybe FilePath,
dterei's avatar
dterei committed
109 110
                -- The source file, if we have one.  Package modules
                -- probably don't have source files.
111 112

        ml_hi_file   :: FilePath,
dterei's avatar
dterei committed
113 114 115
                -- Where the .hi file is, whether or not it exists
                -- yet.  Always of form foo.hi, even if there is an
                -- hi-boot file (we add the -boot suffix later)
116 117

        ml_obj_file  :: FilePath
dterei's avatar
dterei committed
118 119 120 121
                -- Where the .o file is, whether or not it exists yet.
                -- (might not exist either because the module hasn't
                -- been compiled yet, or because it is part of a
                -- package with a .a file)
122
  } deriving Show
123 124 125

instance Outputable ModLocation where
   ppr = text . show
sof's avatar
sof committed
126

Austin Seipp's avatar
Austin Seipp committed
127
{-
128
For a module in another package, the hs_file and obj_file
dterei's avatar
dterei committed
129
components of ModLocation are undefined.
130 131 132 133 134

The locations specified by a ModLocation may or may not
correspond to actual files yet: for example, even if the object
file doesn't exist, the ModLocation still contains the path to
where the object file will reside if/when it is created.
Austin Seipp's avatar
Austin Seipp committed
135
-}
136

137
addBootSuffix :: FilePath -> FilePath
batterseapower's avatar
batterseapower committed
138
-- ^ Add the @-boot@ suffix to .hs, .hi and .o files
139 140 141
addBootSuffix path = path ++ "-boot"

addBootSuffix_maybe :: Bool -> FilePath -> FilePath
batterseapower's avatar
batterseapower committed
142
-- ^ Add the @-boot@ suffix if the @Bool@ argument is @True@
143 144 145 146 147
addBootSuffix_maybe is_boot path
 | is_boot   = addBootSuffix path
 | otherwise = path

addBootSuffixLocn :: ModLocation -> ModLocation
batterseapower's avatar
batterseapower committed
148
-- ^ Add the @-boot@ suffix to all file paths associated with the module
149 150
addBootSuffixLocn locn
  = locn { ml_hs_file  = fmap addBootSuffix (ml_hs_file locn)
dterei's avatar
dterei committed
151 152
         , ml_hi_file  = addBootSuffix (ml_hi_file locn)
         , ml_obj_file = addBootSuffix (ml_obj_file locn) }
sof's avatar
sof committed
153

Austin Seipp's avatar
Austin Seipp committed
154 155 156
{-
************************************************************************
*                                                                      *
sof's avatar
sof committed
157
\subsection{The name of a module}
Austin Seipp's avatar
Austin Seipp committed
158 159 160
*                                                                      *
************************************************************************
-}
sof's avatar
sof committed
161

batterseapower's avatar
batterseapower committed
162
-- | A ModuleName is essentially a simple string, e.g. @Data.List@.
Simon Marlow's avatar
Simon Marlow committed
163
newtype ModuleName = ModuleName FastString
Ian Lynagh's avatar
Ian Lynagh committed
164
    deriving Typeable
165

Simon Marlow's avatar
Simon Marlow committed
166 167
instance Uniquable ModuleName where
  getUnique (ModuleName nm) = getUnique nm
168

Simon Marlow's avatar
Simon Marlow committed
169
instance Eq ModuleName where
170 171 172 173 174
  nm1 == nm2 = getUnique nm1 == getUnique nm2

-- Warning: gives an ordering relation based on the uniques of the
-- FastStrings which are the (encoded) module names.  This is _not_
-- a lexicographical ordering.
Simon Marlow's avatar
Simon Marlow committed
175
instance Ord ModuleName where
176 177
  nm1 `compare` nm2 = getUnique nm1 `compare` getUnique nm2

Simon Marlow's avatar
Simon Marlow committed
178 179
instance Outputable ModuleName where
  ppr = pprModuleName
sof's avatar
sof committed
180

Simon Marlow's avatar
Simon Marlow committed
181 182 183 184
instance Binary ModuleName where
  put_ bh (ModuleName fs) = put_ bh fs
  get bh = do fs <- get bh; return (ModuleName fs)

185 186 187 188
instance BinaryStringRep ModuleName where
  fromStringRep = mkModuleNameFS . mkFastStringByteString
  toStringRep   = fastStringToByteString . moduleNameFS

189 190 191 192 193 194
instance Data ModuleName where
  -- don't traverse?
  toConstr _   = abstractConstr "ModuleName"
  gunfold _ _  = error "gunfold"
  dataTypeOf _ = mkNoRepType "ModuleName"

195
stableModuleNameCmp :: ModuleName -> ModuleName -> Ordering
batterseapower's avatar
batterseapower committed
196
-- ^ Compares module names lexically, rather than by their 'Unique's
197 198
stableModuleNameCmp n1 n2 = moduleNameFS n1 `compare` moduleNameFS n2

Simon Marlow's avatar
Simon Marlow committed
199
pprModuleName :: ModuleName -> SDoc
dterei's avatar
dterei committed
200
pprModuleName (ModuleName nm) =
201
    getPprStyle $ \ sty ->
dterei's avatar
dterei committed
202
    if codeStyle sty
Ian Lynagh's avatar
Ian Lynagh committed
203
        then ztext (zEncodeFS nm)
dterei's avatar
dterei committed
204
        else ftext nm
205

Simon Marlow's avatar
Simon Marlow committed
206 207
moduleNameFS :: ModuleName -> FastString
moduleNameFS (ModuleName mod) = mod
208

Simon Marlow's avatar
Simon Marlow committed
209 210
moduleNameString :: ModuleName -> String
moduleNameString (ModuleName mod) = unpackFS mod
211

Simon Marlow's avatar
Simon Marlow committed
212 213
mkModuleName :: String -> ModuleName
mkModuleName s = ModuleName (mkFastString s)
214

Simon Marlow's avatar
Simon Marlow committed
215 216
mkModuleNameFS :: FastString -> ModuleName
mkModuleNameFS s = ModuleName s
217

218 219
-- |Returns the string version of the module name, with dots replaced by slashes.
--
220 221
moduleNameSlashes :: ModuleName -> String
moduleNameSlashes = dots_to_slashes . moduleNameString
222
  where dots_to_slashes = map (\c -> if c == '.' then pathSeparator else c)
223 224 225 226 227 228

-- |Returns the string version of the module name, with dots replaced by underscores.
--
moduleNameColons :: ModuleName -> String
moduleNameColons = dots_to_colons . moduleNameString
  where dots_to_colons = map (\c -> if c == '.' then ':' else c)
Simon Marlow's avatar
Simon Marlow committed
229

Austin Seipp's avatar
Austin Seipp committed
230 231 232
{-
************************************************************************
*                                                                      *
Simon Marlow's avatar
Simon Marlow committed
233
\subsection{A fully qualified module}
Austin Seipp's avatar
Austin Seipp committed
234 235 236
*                                                                      *
************************************************************************
-}
Simon Marlow's avatar
Simon Marlow committed
237

238
-- | A Module is a pair of a 'PackageKey' and a 'ModuleName'.
Simon Marlow's avatar
Simon Marlow committed
239
data Module = Module {
240
   modulePackageKey :: !PackageKey,  -- pkg-1.0
Simon Marlow's avatar
Simon Marlow committed
241 242
   moduleName      :: !ModuleName  -- A.B.C
  }
Ian Lynagh's avatar
Ian Lynagh committed
243
  deriving (Eq, Ord, Typeable)
Simon Marlow's avatar
Simon Marlow committed
244

batterseapower's avatar
batterseapower committed
245
instance Uniquable Module where
246
  getUnique (Module p n) = getUnique (packageKeyFS p `appendFS` moduleNameFS n)
batterseapower's avatar
batterseapower committed
247

Simon Marlow's avatar
Simon Marlow committed
248 249 250 251 252 253 254
instance Outputable Module where
  ppr = pprModule

instance Binary Module where
  put_ bh (Module p n) = put_ bh p >> put_ bh n
  get bh = do p <- get bh; n <- get bh; return (Module p n)

255 256 257 258 259 260
instance Data Module where
  -- don't traverse?
  toConstr _   = abstractConstr "Module"
  gunfold _ _  = error "gunfold"
  dataTypeOf _ = mkNoRepType "Module"

batterseapower's avatar
batterseapower committed
261 262
-- | This gives a stable ordering, as opposed to the Ord instance which
-- gives an ordering based on the 'Unique's of the components, which may
263 264
-- not be stable from run to run of the compiler.
stableModuleCmp :: Module -> Module -> Ordering
dterei's avatar
dterei committed
265
stableModuleCmp (Module p1 n1) (Module p2 n2)
266
   = (p1 `stablePackageKeyCmp`  p2) `thenCmp`
267
     (n1 `stableModuleNameCmp` n2)
268

269
mkModule :: PackageKey -> ModuleName -> Module
Simon Marlow's avatar
Simon Marlow committed
270 271 272
mkModule = Module

pprModule :: Module -> SDoc
273 274
pprModule mod@(Module p n)  =
  pprPackagePrefix p mod <> pprModuleName n
Simon Marlow's avatar
Simon Marlow committed
275

276
pprPackagePrefix :: PackageKey -> Module -> SDoc
Simon Marlow's avatar
Simon Marlow committed
277 278 279
pprPackagePrefix p mod = getPprStyle doc
 where
   doc sty
dterei's avatar
dterei committed
280
       | codeStyle sty =
281
          if p == mainPackageKey
Simon Marlow's avatar
Simon Marlow committed
282
                then empty -- never qualify the main package in code
283
                else ztext (zEncodeFS (packageKeyFS p)) <> char '_'
284
       | qualModule sty mod = ppr (modulePackageKey mod) <> char ':'
Simon Marlow's avatar
Simon Marlow committed
285 286 287
                -- the PrintUnqualified tells us which modules have to
                -- be qualified with package names
       | otherwise = empty
288 289 290 291 292 293

class ContainsModule t where
    extractModule :: t -> Module

class HasModule m where
    getModule :: m Module
294

Austin Seipp's avatar
Austin Seipp committed
295 296 297
{-
************************************************************************
*                                                                      *
298
\subsection{PackageKey}
Austin Seipp's avatar
Austin Seipp committed
299 300 301
*                                                                      *
************************************************************************
-}
302

303 304 305 306
-- | A string which uniquely identifies a package.  For wired-in packages,
-- it is just the package name, but for user compiled packages, it is a hash.
-- ToDo: when the key is a hash, we can do more clever things than store
-- the hex representation and hash-cons those strings.
307
newtype PackageKey = PId FastString deriving( Eq, Typeable )
308 309
    -- here to avoid module loops with PackageConfig

310 311
instance Uniquable PackageKey where
 getUnique pid = getUnique (packageKeyFS pid)
312 313 314

-- Note: *not* a stable lexicographic ordering, a faster unique-based
-- ordering.
315
instance Ord PackageKey where
316 317
  nm1 `compare` nm2 = getUnique nm1 `compare` getUnique nm2

318
instance Data PackageKey where
319
  -- don't traverse?
320
  toConstr _   = abstractConstr "PackageKey"
321
  gunfold _ _  = error "gunfold"
322
  dataTypeOf _ = mkNoRepType "PackageKey"
323

324
stablePackageKeyCmp :: PackageKey -> PackageKey -> Ordering
batterseapower's avatar
batterseapower committed
325
-- ^ Compares package ids lexically, rather than by their 'Unique's
326
stablePackageKeyCmp p1 p2 = packageKeyFS p1 `compare` packageKeyFS p2
327

328
instance Outputable PackageKey where
329
   ppr pk = getPprStyle $ \sty -> sdocWithDynFlags $ \dflags ->
330 331 332 333 334 335 336
    case packageKeyPackageIdString dflags pk of
      Nothing -> ftext (packageKeyFS pk)
      Just pkg -> text pkg
           -- Don't bother qualifying if it's wired in!
           <> (if qualPackage sty pk && not (pk `elem` wiredInPackageKeys)
                then char '@' <> ftext (packageKeyFS pk)
                else empty)
337

338 339 340
instance Binary PackageKey where
  put_ bh pid = put_ bh (packageKeyFS pid)
  get bh = do { fs <- get bh; return (fsToPackageKey fs) }
341

342 343 344 345
instance BinaryStringRep PackageKey where
  fromStringRep = fsToPackageKey . mkFastStringByteString
  toStringRep   = fastStringToByteString . packageKeyFS

346 347
fsToPackageKey :: FastString -> PackageKey
fsToPackageKey = PId
348

349 350
packageKeyFS :: PackageKey -> FastString
packageKeyFS (PId fs) = fs
351

352 353
stringToPackageKey :: String -> PackageKey
stringToPackageKey = fsToPackageKey . mkFastString
354

355 356
packageKeyString :: PackageKey -> String
packageKeyString = unpackFS . packageKeyFS
357 358 359


-- -----------------------------------------------------------------------------
batterseapower's avatar
batterseapower committed
360 361
-- $wired_in_packages
-- Certain packages are known to the compiler, in that we know about certain
dterei's avatar
dterei committed
362
-- entities that reside in these packages, and the compiler needs to
363 364 365 366 367 368 369 370
-- declare static Modules and Names that refer to these packages.  Hence
-- the wired-in packages can't include version numbers, since we don't want
-- to bake the version numbers of these packages into GHC.
--
-- So here's the plan.  Wired-in packages are still versioned as
-- normal in the packages database, and you can still have multiple
-- versions of them installed.  However, for each invocation of GHC,
-- only a single instance of each wired-in package will be recognised
Ian Lynagh's avatar
Ian Lynagh committed
371
-- (the desired one is selected via @-package@\/@-hide-package@), and GHC
372
-- will use the unversioned 'PackageKey' below when referring to it,
373 374 375
-- including in .hi files and object file symbols.  Unselected
-- versions of wired-in packages will be ignored, as will any other
-- package that depends directly or indirectly on it (much as if you
batterseapower's avatar
batterseapower committed
376 377 378
-- had used @-ignore-package@).

-- Make sure you change 'Packages.findWiredInPackages' if you add an entry here
379

380 381 382 383 384
integerPackageKey, primPackageKey,
  basePackageKey, rtsPackageKey,
  thPackageKey, dphSeqPackageKey, dphParPackageKey,
  mainPackageKey, thisGhcPackageKey, interactivePackageKey  :: PackageKey
primPackageKey        = fsToPackageKey (fsLit "ghc-prim")
385 386 387 388 389
integerPackageKey     = fsToPackageKey (fsLit n)
  where
    n = case cIntegerLibraryType of
        IntegerGMP    -> "integer-gmp"
        IntegerSimple -> "integer-simple"
390 391 392 393 394 395 396
basePackageKey        = fsToPackageKey (fsLit "base")
rtsPackageKey         = fsToPackageKey (fsLit "rts")
thPackageKey          = fsToPackageKey (fsLit "template-haskell")
dphSeqPackageKey      = fsToPackageKey (fsLit "dph-seq")
dphParPackageKey      = fsToPackageKey (fsLit "dph-par")
thisGhcPackageKey     = fsToPackageKey (fsLit "ghc")
interactivePackageKey = fsToPackageKey (fsLit "interactive")
397

batterseapower's avatar
batterseapower committed
398 399 400
-- | This is the package Id for the current program.  It is the default
-- package Id if you don't specify a package name.  We don't add this prefix
-- to symbol names, since there can be only one main package per program.
401
mainPackageKey      = fsToPackageKey (fsLit "main")
402

403 404 405 406 407
-- | This is a fake package id used to provide identities to any un-implemented
-- signatures.  The set of hole identities is global over an entire compilation.
holePackageKey :: PackageKey
holePackageKey      = fsToPackageKey (fsLit "hole")

408
isInteractiveModule :: Module -> Bool
409
isInteractiveModule mod = modulePackageKey mod == interactivePackageKey
410

411 412 413
isHoleModule :: Module -> Bool
isHoleModule mod = modulePackageKey mod == holePackageKey

414 415 416 417 418 419 420 421 422
wiredInPackageKeys :: [PackageKey]
wiredInPackageKeys = [ primPackageKey,
                       integerPackageKey,
                       basePackageKey,
                       rtsPackageKey,
                       thPackageKey,
                       thisGhcPackageKey,
                       dphSeqPackageKey,
                       dphParPackageKey ]
423

Austin Seipp's avatar
Austin Seipp committed
424 425 426
{-
************************************************************************
*                                                                      *
427
\subsection{@ModuleEnv@s}
Austin Seipp's avatar
Austin Seipp committed
428 429 430
*                                                                      *
************************************************************************
-}
431

batterseapower's avatar
batterseapower committed
432
-- | A map keyed off of 'Module's
433
newtype ModuleEnv elt = ModuleEnv (Map Module elt)
434 435

filterModuleEnv :: (Module -> a -> Bool) -> ModuleEnv a -> ModuleEnv a
436
filterModuleEnv f (ModuleEnv e) = ModuleEnv (Map.filterWithKey f e)
437 438

elemModuleEnv :: Module -> ModuleEnv a -> Bool
439
elemModuleEnv m (ModuleEnv e) = Map.member m e
440 441

extendModuleEnv :: ModuleEnv a -> Module -> a -> ModuleEnv a
442
extendModuleEnv (ModuleEnv e) m x = ModuleEnv (Map.insert m x e)
443

444 445
extendModuleEnvWith :: (a -> a -> a) -> ModuleEnv a -> Module -> a -> ModuleEnv a
extendModuleEnvWith f (ModuleEnv e) m x = ModuleEnv (Map.insertWith f m x e)
446 447

extendModuleEnvList :: ModuleEnv a -> [(Module, a)] -> ModuleEnv a
448
extendModuleEnvList (ModuleEnv e) xs = ModuleEnv (Map.insertList xs e)
449 450 451

extendModuleEnvList_C :: (a -> a -> a) -> ModuleEnv a -> [(Module, a)]
                      -> ModuleEnv a
452
extendModuleEnvList_C f (ModuleEnv e) xs = ModuleEnv (Map.insertListWith f xs e)
453 454

plusModuleEnv_C :: (a -> a -> a) -> ModuleEnv a -> ModuleEnv a -> ModuleEnv a
455
plusModuleEnv_C f (ModuleEnv e1) (ModuleEnv e2) = ModuleEnv (Map.unionWith f e1 e2)
456 457

delModuleEnvList :: ModuleEnv a -> [Module] -> ModuleEnv a
458
delModuleEnvList (ModuleEnv e) ms = ModuleEnv (Map.deleteList ms e)
459 460

delModuleEnv :: ModuleEnv a -> Module -> ModuleEnv a
461
delModuleEnv (ModuleEnv e) m = ModuleEnv (Map.delete m e)
462 463

plusModuleEnv :: ModuleEnv a -> ModuleEnv a -> ModuleEnv a
464
plusModuleEnv (ModuleEnv e1) (ModuleEnv e2) = ModuleEnv (Map.union e1 e2)
465 466

lookupModuleEnv :: ModuleEnv a -> Module -> Maybe a
467
lookupModuleEnv (ModuleEnv e) m = Map.lookup m e
468

469
lookupWithDefaultModuleEnv :: ModuleEnv a -> a -> Module -> a
470
lookupWithDefaultModuleEnv (ModuleEnv e) x m = Map.findWithDefault x m e
471 472

mapModuleEnv :: (a -> b) -> ModuleEnv a -> ModuleEnv b
473
mapModuleEnv f (ModuleEnv e) = ModuleEnv (Map.mapWithKey (\_ v -> f v) e)
474 475

mkModuleEnv :: [(Module, a)] -> ModuleEnv a
476
mkModuleEnv xs = ModuleEnv (Map.fromList xs)
477 478

emptyModuleEnv :: ModuleEnv a
479
emptyModuleEnv = ModuleEnv Map.empty
480 481

moduleEnvKeys :: ModuleEnv a -> [Module]
482
moduleEnvKeys (ModuleEnv e) = Map.keys e
483 484

moduleEnvElts :: ModuleEnv a -> [a]
485
moduleEnvElts (ModuleEnv e) = Map.elems e
486 487

moduleEnvToList :: ModuleEnv a -> [(Module, a)]
488
moduleEnvToList (ModuleEnv e) = Map.toList e
489 490

unitModuleEnv :: Module -> a -> ModuleEnv a
491
unitModuleEnv m x = ModuleEnv (Map.singleton m x)
492 493

isEmptyModuleEnv :: ModuleEnv a -> Bool
494
isEmptyModuleEnv (ModuleEnv e) = Map.null e
495 496

foldModuleEnv :: (a -> b -> b) -> b -> ModuleEnv a -> b
497
foldModuleEnv f x (ModuleEnv e) = Map.foldRightWithKey (\_ v -> f v) x e
498

batterseapower's avatar
batterseapower committed
499
-- | A set of 'Module's
500
type ModuleSet = Map Module ()
batterseapower's avatar
batterseapower committed
501

dterei's avatar
dterei committed
502
mkModuleSet     :: [Module] -> ModuleSet
503 504 505 506 507
extendModuleSet :: ModuleSet -> Module -> ModuleSet
emptyModuleSet  :: ModuleSet
moduleSetElts   :: ModuleSet -> [Module]
elemModuleSet   :: Module -> ModuleSet -> Bool

508 509 510 511 512
emptyModuleSet    = Map.empty
mkModuleSet ms    = Map.fromList [(m,()) | m <- ms ]
extendModuleSet s m = Map.insert m () s
moduleSetElts     = Map.keys
elemModuleSet     = Map.member
Simon Marlow's avatar
Simon Marlow committed
513

Austin Seipp's avatar
Austin Seipp committed
514
{-
Simon Marlow's avatar
Simon Marlow committed
515 516
A ModuleName has a Unique, so we can build mappings of these using
UniqFM.
Austin Seipp's avatar
Austin Seipp committed
517
-}
Simon Marlow's avatar
Simon Marlow committed
518

batterseapower's avatar
batterseapower committed
519
-- | A map keyed off of 'ModuleName's (actually, their 'Unique's)
Simon Marlow's avatar
Simon Marlow committed
520
type ModuleNameEnv elt = UniqFM elt