Names.hs 108 KB
Newer Older
Austin Seipp's avatar
Austin Seipp committed
1 2 3
{-
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

Sylvain Henry's avatar
Sylvain Henry committed
4
\section[GHC.Builtin.Names]{Definitions of prelude modules and names}
5 6


7
Nota Bene: all Names defined in here should come from the base package
8

9 10
 - ModuleNames for prelude modules,
        e.g.    pREL_BASE_Name :: ModuleName
11

Thomas Schilling's avatar
Thomas Schilling committed
12
 - Modules for prelude modules
13
        e.g.    pREL_Base :: Module
14

15
 - Uniques for Ids, DataCons, TyCons and Classes that the compiler
Thomas Schilling's avatar
Thomas Schilling committed
16
   "knows about" in some way
17 18
        e.g.    intTyConKey :: Unique
                minusClassOpKey :: Unique
19

20
 - Names for Ids, DataCons, TyCons and Classes that the compiler
Thomas Schilling's avatar
Thomas Schilling committed
21
   "knows about" in some way
22 23
        e.g.    intTyConName :: Name
                minusName    :: Name
Thomas Schilling's avatar
Thomas Schilling committed
24
   One of these Names contains
25 26
        (a) the module and occurrence name of the thing
        (b) its Unique
Peter Trommler's avatar
Peter Trommler committed
27
   The way the compiler "knows about" one of these things is
Thomas Schilling's avatar
Thomas Schilling committed
28 29 30 31
   where the type checker or desugarer needs to look it up. For
   example, when desugaring list comprehensions the desugarer
   needs to conjure up 'foldr'.  It does this by looking up
   foldrName in the environment.
32

Thomas Schilling's avatar
Thomas Schilling committed
33 34 35
 - RdrNames for Ids, DataCons etc that the compiler may emit into
   generated code (e.g. for deriving).  It's not necessary to know
   the uniques for these guys, only their names
36

37

38 39
Note [Known-key names]
~~~~~~~~~~~~~~~~~~~~~~
40 41 42
It is *very* important that the compiler gives wired-in things and
things with "known-key" names the correct Uniques wherever they
occur. We have to be careful about this in exactly two places:
43

44 45
  1. When we parse some source code, renaming the AST better yield an
     AST whose Names have the correct uniques
46

47 48
  2. When we read an interface file, the read-in gubbins better have
     the right uniques
49 50 51

This is accomplished through a combination of mechanisms:

52 53 54 55 56 57 58 59 60 61 62 63 64 65
  1. When parsing source code, the RdrName-decorated AST has some
     RdrNames which are Exact. These are wired-in RdrNames where the
     we could directly tell from the parsed syntax what Name to
     use. For example, when we parse a [] in a type we can just insert
     an Exact RdrName Name with the listTyConKey.

     Currently, I believe this is just an optimisation: it would be
     equally valid to just output Orig RdrNames that correctly record
     the module etc we expect the final Name to come from. However,
     were we to eliminate isBuiltInOcc_maybe it would become essential
     (see point 3).

  2. The knownKeyNames (which consist of the basicKnownKeyNames from
     the module, and those names reachable via the wired-in stuff from
Sylvain Henry's avatar
Sylvain Henry committed
66
     GHC.Builtin.Types) are used to initialise the "OrigNameCache" in
67 68
     GHC.Iface.Env.  This initialization ensures that when the type checker
     or renamer (both of which use GHC.Iface.Env) look up an original name
69 70 71 72 73 74 75
     (i.e. a pair of a Module and an OccName) for a known-key name
     they get the correct Unique.

     This is the most important mechanism for ensuring that known-key
     stuff gets the right Unique, and is why it is so important to
     place your known-key names in the appropriate lists.

76 77
  3. For "infinite families" of known-key names (i.e. tuples and sums), we
     have to be extra careful. Because there are an infinite number of
78 79
     these things, we cannot add them to the list of known-key names
     used to initialise the OrigNameCache. Instead, we have to
80 81
     rely on never having to look them up in that cache. See
     Note [Infinite families of known-key names] for details.
82 83


84 85 86 87 88 89
Note [Infinite families of known-key names]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Infinite families of known-key things (e.g. tuples and sums) pose a tricky
problem: we can't add them to the knownKeyNames finite map which we use to
ensure that, e.g., a reference to (,) gets assigned the right unique (if this
doesn't sound familiar see Note [Known-key names] above).
90

91 92
We instead handle tuples and sums separately from the "vanilla" known-key
things,
93

94 95
  a) The parser recognises them specially and generates an Exact Name (hence not
     looked up in the orig-name cache)
96

97
  b) The known infinite families of names are specially serialised by
98 99 100
     GHC.Iface.Binary.putName, with that special treatment detected when we read
     back to ensure that we get back to the correct uniques. See Note [Symbol
     table representation of names] in GHC.Iface.Binary and Note [How tuples
Sylvain Henry's avatar
Sylvain Henry committed
101
     work] in GHC.Builtin.Types.
102 103 104 105 106 107

Most of the infinite families cannot occur in source code, so mechanisms (a) and (b)
suffice to ensure that they always have the right Unique. In particular,
implicit param TyCon names, constraint tuples and Any TyCons cannot be mentioned
by the user. For those things that *can* appear in source programs,

108
  c) GHC.Iface.Env.lookupOrigNameCache uses isBuiltInOcc_maybe to map built-in syntax
109 110 111 112
     directly onto the corresponding name, rather than trying to find it in the
     original-name cache.

     See also Note [Built-in syntax and the OrigNameCache]
113

114 115 116 117
Note that one-tuples are an exception to the rule, as they do get assigned
known keys. See
Note [One-tuples] (Wrinkle: Make boxed one-tuple names have known keys)
in GHC.Builtin.Types.
118

Austin Seipp's avatar
Austin Seipp committed
119
-}
120

121
{-# LANGUAGE CPP #-}
122
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns   #-}
123

Sylvain Henry's avatar
Sylvain Henry committed
124 125
module GHC.Builtin.Names
   ( Unique, Uniquable(..), hasKey,  -- Re-exported for convenience
126

Sylvain Henry's avatar
Sylvain Henry committed
127 128 129 130 131 132 133 134
   -----------------------------------------------------------
   module GHC.Builtin.Names, -- A huge bunch of (a) Names,  e.g. intTyConName
                             --                 (b) Uniques e.g. intTyConKey
                             --                 (c) Groups of classes and types
                             --                 (d) miscellaneous things
                             -- So many that we export them all
   )
where
135 136 137

#include "HsVersions.h"

138
import GHC.Prelude
139

Sylvain Henry's avatar
Sylvain Henry committed
140 141
import GHC.Unit.Types
import GHC.Unit.Module.Name
Sylvain Henry's avatar
Sylvain Henry committed
142 143 144
import GHC.Types.Name.Occurrence
import GHC.Types.Name.Reader
import GHC.Types.Unique
Aditya Gupta's avatar
Aditya Gupta committed
145
import GHC.Builtin.Uniques
Sylvain Henry's avatar
Sylvain Henry committed
146 147
import GHC.Types.Name
import GHC.Types.SrcLoc
148
import GHC.Data.FastString
149

Austin Seipp's avatar
Austin Seipp committed
150 151 152
{-
************************************************************************
*                                                                      *
153
     allNameStrings
Austin Seipp's avatar
Austin Seipp committed
154 155 156
*                                                                      *
************************************************************************
-}
157 158 159

allNameStrings :: [String]
-- Infinite list of a,b,c...z, aa, ab, ac, ... etc
160
allNameStrings = [ c:cs | cs <- "" : allNameStrings, c <- ['a'..'z'] ]
161

Austin Seipp's avatar
Austin Seipp committed
162 163 164
{-
************************************************************************
*                                                                      *
165
\subsection{Local Names}
Austin Seipp's avatar
Austin Seipp committed
166 167
*                                                                      *
************************************************************************
168 169

This *local* name is used by the interactive stuff
Austin Seipp's avatar
Austin Seipp committed
170
-}
171

172 173
itName :: Unique -> SrcSpan -> Name
itName uniq loc = mkInternalName uniq (mkOccNameFS varName (fsLit "it")) loc
174 175 176

-- mkUnboundName makes a place-holder Name; it shouldn't be looked at except possibly
-- during compiler debugging.
177 178
mkUnboundName :: OccName -> Name
mkUnboundName occ = mkInternalName unboundKey occ noSrcSpan
179 180 181 182

isUnboundName :: Name -> Bool
isUnboundName name = name `hasKey` unboundKey

Austin Seipp's avatar
Austin Seipp committed
183 184 185
{-
************************************************************************
*                                                                      *
186
\subsection{Known key Names}
Austin Seipp's avatar
Austin Seipp committed
187 188
*                                                                      *
************************************************************************
189

190
This section tells what the compiler knows about the association of
191
names with uniques.  These ones are the *non* wired-in ones.  The
Sylvain Henry's avatar
Sylvain Henry committed
192
wired in ones are defined in GHC.Builtin.Types etc.
Austin Seipp's avatar
Austin Seipp committed
193
-}
194

Simon Peyton Jones's avatar
Simon Peyton Jones committed
195
basicKnownKeyNames :: [Name]  -- See Note [Known-key names]
196
basicKnownKeyNames
197
 = genericTyConNames
Ben Gamari's avatar
Ben Gamari committed
198
 ++ [   --  Classes.  *Must* include:
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        --      classes that are grabbed by key (e.g., eqClassKey)
        --      classes in "Class.standardClassKeys" (quite a few)
        eqClassName,                    -- mentioned, derivable
        ordClassName,                   -- derivable
        boundedClassName,               -- derivable
        numClassName,                   -- mentioned, numeric
        enumClassName,                  -- derivable
        monadClassName,
        functorClassName,
        realClassName,                  -- numeric
        integralClassName,              -- numeric
        fractionalClassName,            -- numeric
        floatingClassName,              -- numeric
        realFracClassName,              -- numeric
        realFloatClassName,             -- numeric
        dataClassName,
        isStringClassName,
        applicativeClassName,
217
        alternativeClassName,
218 219
        foldableClassName,
        traversableClassName,
220 221
        semigroupClassName, sappendName,
        monoidClassName, memptyName, mappendName, mconcatName,
222

Ben Gamari's avatar
Ben Gamari committed
223 224 225 226
        -- The IO type
        -- See Note [TyConRepNames for non-wired-in TyCons]
        ioTyConName, ioDataConName,
        runMainIOName,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
227
        runRWName,
Ben Gamari's avatar
Ben Gamari committed
228

229 230 231 232 233
        -- Type representation types
        trModuleTyConName, trModuleDataConName,
        trNameTyConName, trNameSDataConName, trNameDDataConName,
        trTyConTyConName, trTyConDataConName,

234 235 236
        -- Typeable
        typeableClassName,
        typeRepTyConName,
Ben Gamari's avatar
Ben Gamari committed
237 238 239 240 241 242 243 244 245 246 247 248 249
        someTypeRepTyConName,
        someTypeRepDataConName,
        kindRepTyConName,
        kindRepTyConAppDataConName,
        kindRepVarDataConName,
        kindRepAppDataConName,
        kindRepFunDataConName,
        kindRepTYPEDataConName,
        kindRepTypeLitSDataConName,
        kindRepTypeLitDDataConName,
        typeLitSortTyConName,
        typeLitSymbolDataConName,
        typeLitNatDataConName,
250
        typeRepIdName,
David Feuer's avatar
David Feuer committed
251
        mkTrTypeName,
Ben Gamari's avatar
Ben Gamari committed
252 253 254
        mkTrConName,
        mkTrAppName,
        mkTrFunName,
255
        typeSymbolTypeRepName, typeNatTypeRepName,
256
        trGhcPrimModuleName,
257

258 259 260 261 262
        -- KindReps for common cases
        starKindRepName,
        starArrStarKindRepName,
        starArrStarArrStarKindRepName,

263 264
        -- Dynamic
        toDynName,
265 266

        -- Numeric stuff
267 268 269
        negateName, minusName, geName, eqName,

        -- Conversion functions
Ben Gamari's avatar
Ben Gamari committed
270 271
        rationalTyConName,
        ratioTyConName, ratioDataConName,
272 273 274
        fromRationalName, fromIntegerName,
        toIntegerName, toRationalName,
        fromIntegralName, realToFracName,
275

276 277 278
        -- Int# stuff
        divIntName, modIntName,

279 280
        -- String stuff
        fromStringName,
281 282 283 284 285

        -- Enum stuff
        enumFromName, enumFromThenName,
        enumFromThenToName, enumFromToName,

286 287
        -- Applicative stuff
        pureAName, apAName, thenAName,
288

David Feuer's avatar
David Feuer committed
289 290 291
        -- Functor stuff
        fmapName,

292
        -- Monad stuff
quchen's avatar
quchen committed
293
        thenIOName, bindIOName, returnIOName, failIOName, bindMName, thenMName,
David Feuer's avatar
David Feuer committed
294
        returnMName, joinMName,
quchen's avatar
quchen committed
295 296

        -- MonadFail
297
        monadFailClassName, failMName,
298

299 300
        -- MonadFix
        monadFixClassName, mfixName,
301

302 303 304
        -- Arrow stuff
        arrAName, composeAName, firstAName,
        appAName, choiceAName, loopAName,
305

306 307
        -- Ix stuff
        ixClassName,
308

309 310
        -- Show stuff
        showClassName,
311

312 313
        -- Read stuff
        readClassName,
314

315 316
        -- Stable pointers
        newStablePtrName,
317

318
        -- GHC Extensions
319
        groupWithName,
320

321
        -- Strings and lists
Andreas Klebinger's avatar
Andreas Klebinger committed
322 323
        unpackCStringName, unpackCStringUtf8Name,
        unpackCStringFoldrName, unpackCStringFoldrUtf8Name,
324
        cstringLengthName,
325

326 327 328 329 330
        -- Overloaded lists
        isListClassName,
        fromListName,
        fromListNName,
        toListName,
331

332 333 334
        -- List operations
        concatName, filterName, mapName,
        zipName, foldrName, buildName, augmentName, appendName,
335

336 337 338
        -- FFI primitive types that are not wired-in.
        stablePtrTyConName, ptrTyConName, funPtrTyConName,
        int8TyConName, int16TyConName, int32TyConName, int64TyConName,
339
        word16TyConName, word32TyConName, word64TyConName,
340

341 342 343
        -- Others
        otherwiseIdName, inlineIdName,
        eqStringName, assertName, breakpointName, breakpointCondName,
344
        opaqueTyConName,
David Feuer's avatar
David Feuer committed
345
        assertErrorName, traceName,
346
        printName, fstName, sndName,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
347
        dollarName,
348

Sylvain Henry's avatar
Sylvain Henry committed
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
        -- ghc-bignum
        integerFromNaturalName,
        integerToNaturalClampName,
        integerToWordName,
        integerToIntName,
        integerToWord64Name,
        integerToInt64Name,
        integerFromWordName,
        integerFromWord64Name,
        integerFromInt64Name,
        integerAddName,
        integerMulName,
        integerSubName,
        integerNegateName,
        integerEqPrimName,
        integerNePrimName,
        integerLePrimName,
        integerGtPrimName,
        integerLtPrimName,
        integerGePrimName,
        integerAbsName,
        integerSignumName,
        integerCompareName,
        integerQuotName,
        integerRemName,
        integerDivName,
        integerModName,
        integerDivModName,
        integerQuotRemName,
        integerToFloatName,
        integerToDoubleName,
        integerEncodeFloatName,
        integerEncodeDoubleName,
        integerGcdName,
        integerLcmName,
        integerAndName,
        integerOrName,
        integerXorName,
        integerComplementName,
        integerBitName,
        integerShiftLName,
        integerShiftRName,
        naturalToWordName,
        naturalAddName,
        naturalSubName,
        naturalMulName,
        naturalQuotName,
        naturalRemName,
        naturalQuotRemName,
        bignatFromWordListName,
399 400 401 402
        -- Float/Double
        rationalToFloatName,
        rationalToDoubleName,

403 404
        -- Other classes
        randomClassName, randomGenClassName, monadPlusClassName,
405

406
        -- Type-level naturals
407
        knownNatClassName, knownSymbolClassName,
408

Adam Gundry's avatar
Adam Gundry committed
409 410 411
        -- Overloaded labels
        isLabelClassName,

412 413 414
        -- Implicit Parameters
        ipClassName,

415 416 417
        -- Overloaded record fields
        hasFieldClassName,

418 419
        -- Call Stacks
        callStackTyConName,
Eric Seidel's avatar
Eric Seidel committed
420
        emptyCallStackName, pushCallStackName,
421 422

        -- Source Locations
423 424
        srcLocDataConName,

425
        -- Annotation type checking
426
        toAnnotationWrapperName
427

428 429 430
        -- The SPEC type for SpecConstr
        , specTyConName

431 432
        -- The Either type
        , eitherTyConName, leftDataConName, rightDataConName
433

434 435
        -- Plugins
        , pluginTyConName
Edward Z. Yang's avatar
Edward Z. Yang committed
436
        , frontendPluginTyConName
437 438 439 440 441

        -- Generics
        , genClassName, gen1ClassName
        , datatypeClassName, constructorClassName, selectorClassName

442 443 444 445
        -- Monad comprehensions
        , guardMName
        , liftMName
        , mzipName
dterei's avatar
dterei committed
446 447 448

        -- GHCi Sandbox
        , ghciIoClassName, ghciStepIoMName
Facundo Domínguez's avatar
Facundo Domínguez committed
449 450

        -- StaticPtr
451
        , makeStaticName
Facundo Domínguez's avatar
Facundo Domínguez committed
452 453
        , staticPtrTyConName
        , staticPtrDataConName, staticPtrInfoDataConName
454
        , fromStaticPtrName
Facundo Domínguez's avatar
Facundo Domínguez committed
455 456 457 458

        -- Fingerprint
        , fingerprintDataConName

459 460 461 462 463 464 465
        -- Custom type errors
        , errorMessageTypeErrorFamName
        , typeErrorTextDataConName
        , typeErrorAppendDataConName
        , typeErrorVAppendDataConName
        , typeErrorShowTypeDataConName

466 467 468 469 470
        -- Unsafe coercion proofs
        , unsafeEqualityProofName
        , unsafeEqualityTyConName
        , unsafeReflDataConName
        , unsafeCoercePrimName
471
    ]
472

473
genericTyConNames :: [Name]
474 475 476
genericTyConNames = [
    v1TyConName, u1TyConName, par1TyConName, rec1TyConName,
    k1TyConName, m1TyConName, sumTyConName, prodTyConName,
477 478
    compTyConName, rTyConName, dTyConName,
    cTyConName, sTyConName, rec0TyConName,
479
    d1TyConName, c1TyConName, s1TyConName, noSelTyConName,
480 481
    repTyConName, rep1TyConName, uRecTyConName,
    uAddrTyConName, uCharTyConName, uDoubleTyConName,
482 483 484
    uFloatTyConName, uIntTyConName, uWordTyConName,
    prefixIDataConName, infixIDataConName, leftAssociativeDataConName,
    rightAssociativeDataConName, notAssociativeDataConName,
485 486 487 488 489
    sourceUnpackDataConName, sourceNoUnpackDataConName,
    noSourceUnpackednessDataConName, sourceLazyDataConName,
    sourceStrictDataConName, noSourceStrictnessDataConName,
    decidedLazyDataConName, decidedStrictDataConName, decidedUnpackDataConName,
    metaDataDataConName, metaConsDataConName, metaSelDataConName
490
  ]
491

Austin Seipp's avatar
Austin Seipp committed
492 493 494
{-
************************************************************************
*                                                                      *
495
\subsection{Module names}
Austin Seipp's avatar
Austin Seipp committed
496 497
*                                                                      *
************************************************************************
498

499 500

--MetaHaskell Extension Add a new module here
Austin Seipp's avatar
Austin Seipp committed
501 502
-}

Ian Lynagh's avatar
Ian Lynagh committed
503
pRELUDE :: Module
504
pRELUDE         = mkBaseModule_ pRELUDE_NAME
Ian Lynagh's avatar
Ian Lynagh committed
505

Sylvain Henry's avatar
Sylvain Henry committed
506 507
gHC_PRIM, gHC_PRIM_PANIC, gHC_PRIM_EXCEPTION,
    gHC_TYPES, gHC_GENERICS, gHC_MAGIC,
508 509
    gHC_CLASSES, gHC_PRIMOPWRAPPERS, gHC_BASE, gHC_ENUM,
    gHC_GHCI, gHC_GHCI_HELPERS, gHC_CSTRING,
Sylvain Henry's avatar
Sylvain Henry committed
510 511
    gHC_SHOW, gHC_READ, gHC_NUM, gHC_MAYBE,
    gHC_NUM_INTEGER, gHC_NUM_NATURAL, gHC_NUM_BIGNAT,
512
    gHC_LIST, gHC_TUPLE, dATA_TUPLE, dATA_EITHER, dATA_LIST, dATA_STRING,
513
    dATA_FOLDABLE, dATA_TRAVERSABLE,
dterei's avatar
dterei committed
514
    gHC_CONC, gHC_IO, gHC_IO_Exception,
Ben Gamari's avatar
Ben Gamari committed
515
    gHC_ST, gHC_IX, gHC_STABLE, gHC_PTR, gHC_ERR, gHC_REAL,
516
    gHC_FLOAT, gHC_TOP_HANDLER, sYSTEM_IO, dYNAMIC,
517
    tYPEABLE, tYPEABLE_INTERNAL, gENERICS,
quchen's avatar
quchen committed
518
    rEAD_PREC, lEX, gHC_INT, gHC_WORD, mONAD, mONAD_FIX, mONAD_ZIP, mONAD_FAIL,
519
    aRROW, cONTROL_APPLICATIVE, gHC_DESUGAR, rANDOM, gHC_EXTS,
520
    cONTROL_EXCEPTION_BASE, gHC_TYPELITS, gHC_TYPENATS, dATA_TYPE_EQUALITY,
521
    dATA_COERCE, dEBUG_TRACE, uNSAFE_COERCE :: Module
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
522

523
gHC_PRIM        = mkPrimModule (fsLit "GHC.Prim")   -- Primitive types and values
524
gHC_PRIM_PANIC  = mkPrimModule (fsLit "GHC.Prim.Panic")
Sylvain Henry's avatar
Sylvain Henry committed
525
gHC_PRIM_EXCEPTION = mkPrimModule (fsLit "GHC.Prim.Exception")
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
526
gHC_TYPES       = mkPrimModule (fsLit "GHC.Types")
527 528 529
gHC_MAGIC       = mkPrimModule (fsLit "GHC.Magic")
gHC_CSTRING     = mkPrimModule (fsLit "GHC.CString")
gHC_CLASSES     = mkPrimModule (fsLit "GHC.Classes")
530
gHC_PRIMOPWRAPPERS = mkPrimModule (fsLit "GHC.PrimopWrappers")
531 532 533

gHC_BASE        = mkBaseModule (fsLit "GHC.Base")
gHC_ENUM        = mkBaseModule (fsLit "GHC.Enum")
dterei's avatar
dterei committed
534
gHC_GHCI        = mkBaseModule (fsLit "GHC.GHCi")
535
gHC_GHCI_HELPERS= mkBaseModule (fsLit "GHC.GHCi.Helpers")
536 537 538
gHC_SHOW        = mkBaseModule (fsLit "GHC.Show")
gHC_READ        = mkBaseModule (fsLit "GHC.Read")
gHC_NUM         = mkBaseModule (fsLit "GHC.Num")
539
gHC_MAYBE       = mkBaseModule (fsLit "GHC.Maybe")
Sylvain Henry's avatar
Sylvain Henry committed
540 541 542
gHC_NUM_INTEGER = mkBignumModule (fsLit "GHC.Num.Integer")
gHC_NUM_NATURAL = mkBignumModule (fsLit "GHC.Num.Natural")
gHC_NUM_BIGNAT  = mkBignumModule (fsLit "GHC.Num.BigNat")
543 544 545
gHC_LIST        = mkBaseModule (fsLit "GHC.List")
gHC_TUPLE       = mkPrimModule (fsLit "GHC.Tuple")
dATA_TUPLE      = mkBaseModule (fsLit "Data.Tuple")
546
dATA_EITHER     = mkBaseModule (fsLit "Data.Either")
547
dATA_LIST       = mkBaseModule (fsLit "Data.List")
548 549
dATA_STRING     = mkBaseModule (fsLit "Data.String")
dATA_FOLDABLE   = mkBaseModule (fsLit "Data.Foldable")
550
dATA_TRAVERSABLE= mkBaseModule (fsLit "Data.Traversable")
551 552
gHC_CONC        = mkBaseModule (fsLit "GHC.Conc")
gHC_IO          = mkBaseModule (fsLit "GHC.IO")
553
gHC_IO_Exception = mkBaseModule (fsLit "GHC.IO.Exception")
554
gHC_ST          = mkBaseModule (fsLit "GHC.ST")
Ben Gamari's avatar
Ben Gamari committed
555
gHC_IX          = mkBaseModule (fsLit "GHC.Ix")
556 557 558 559 560 561 562 563
gHC_STABLE      = mkBaseModule (fsLit "GHC.Stable")
gHC_PTR         = mkBaseModule (fsLit "GHC.Ptr")
gHC_ERR         = mkBaseModule (fsLit "GHC.Err")
gHC_REAL        = mkBaseModule (fsLit "GHC.Real")
gHC_FLOAT       = mkBaseModule (fsLit "GHC.Float")
gHC_TOP_HANDLER = mkBaseModule (fsLit "GHC.TopHandler")
sYSTEM_IO       = mkBaseModule (fsLit "System.IO")
dYNAMIC         = mkBaseModule (fsLit "Data.Dynamic")
564 565
tYPEABLE        = mkBaseModule (fsLit "Data.Typeable")
tYPEABLE_INTERNAL = mkBaseModule (fsLit "Data.Typeable.Internal")
566
gENERICS        = mkBaseModule (fsLit "Data.Data")
567 568 569 570 571 572
rEAD_PREC       = mkBaseModule (fsLit "Text.ParserCombinators.ReadPrec")
lEX             = mkBaseModule (fsLit "Text.Read.Lex")
gHC_INT         = mkBaseModule (fsLit "GHC.Int")
gHC_WORD        = mkBaseModule (fsLit "GHC.Word")
mONAD           = mkBaseModule (fsLit "Control.Monad")
mONAD_FIX       = mkBaseModule (fsLit "Control.Monad.Fix")
573
mONAD_ZIP       = mkBaseModule (fsLit "Control.Monad.Zip")
quchen's avatar
quchen committed
574
mONAD_FAIL      = mkBaseModule (fsLit "Control.Monad.Fail")
575
aRROW           = mkBaseModule (fsLit "Control.Arrow")
576
cONTROL_APPLICATIVE = mkBaseModule (fsLit "Control.Applicative")
Ian Lynagh's avatar
Ian Lynagh committed
577
gHC_DESUGAR = mkBaseModule (fsLit "GHC.Desugar")
578 579
rANDOM          = mkBaseModule (fsLit "System.Random")
gHC_EXTS        = mkBaseModule (fsLit "GHC.Exts")
580
cONTROL_EXCEPTION_BASE = mkBaseModule (fsLit "Control.Exception.Base")
jpm@cs.ox.ac.uk's avatar
jpm@cs.ox.ac.uk committed
581
gHC_GENERICS    = mkBaseModule (fsLit "GHC.Generics")
582
gHC_TYPELITS    = mkBaseModule (fsLit "GHC.TypeLits")
583
gHC_TYPENATS    = mkBaseModule (fsLit "GHC.TypeNats")
584 585
dATA_TYPE_EQUALITY = mkBaseModule (fsLit "Data.Type.Equality")
dATA_COERCE     = mkBaseModule (fsLit "Data.Coerce")
David Feuer's avatar
David Feuer committed
586
dEBUG_TRACE     = mkBaseModule (fsLit "Debug.Trace")
587
uNSAFE_COERCE   = mkBaseModule (fsLit "Unsafe.Coerce")
Simon Marlow's avatar
Simon Marlow committed
588

589 590 591
gHC_SRCLOC :: Module
gHC_SRCLOC = mkBaseModule (fsLit "GHC.SrcLoc")

Ben Gamari's avatar
Ben Gamari committed
592
gHC_STACK, gHC_STACK_TYPES :: Module
593
gHC_STACK = mkBaseModule (fsLit "GHC.Stack")
Ben Gamari's avatar
Ben Gamari committed
594
gHC_STACK_TYPES = mkBaseModule (fsLit "GHC.Stack.Types")
595

Facundo Domínguez's avatar
Facundo Domínguez committed
596 597 598
gHC_STATICPTR :: Module
gHC_STATICPTR = mkBaseModule (fsLit "GHC.StaticPtr")

599 600 601
gHC_STATICPTR_INTERNAL :: Module
gHC_STATICPTR_INTERNAL = mkBaseModule (fsLit "GHC.StaticPtr.Internal")

Facundo Domínguez's avatar
Facundo Domínguez committed
602 603 604
gHC_FINGERPRINT_TYPE :: Module
gHC_FINGERPRINT_TYPE = mkBaseModule (fsLit "GHC.Fingerprint.Type")

Adam Gundry's avatar
Adam Gundry committed
605 606 607
gHC_OVER_LABELS :: Module
gHC_OVER_LABELS = mkBaseModule (fsLit "GHC.OverloadedLabels")

608 609 610
gHC_RECORDS :: Module
gHC_RECORDS = mkBaseModule (fsLit "GHC.Records")

fendor's avatar
fendor committed
611
rOOT_MAIN :: Module
612
rOOT_MAIN       = mkMainModule (fsLit ":Main") -- Root module for initialisation
Simon Marlow's avatar
Simon Marlow committed
613

614 615
mkInteractiveModule :: Int -> Module
-- (mkInteractiveMoudule 9) makes module 'interactive:M9'
Sylvain Henry's avatar
Sylvain Henry committed
616
mkInteractiveModule n = mkModule interactiveUnit (mkModuleName ("Ghci" ++ show n))
Simon Marlow's avatar
Simon Marlow committed
617

Ian Lynagh's avatar
Ian Lynagh committed
618
pRELUDE_NAME, mAIN_NAME :: ModuleName
Ian Lynagh's avatar
Ian Lynagh committed
619 620
pRELUDE_NAME   = mkModuleNameFS (fsLit "Prelude")
mAIN_NAME      = mkModuleNameFS (fsLit "Main")
Simon Marlow's avatar
Simon Marlow committed
621

622 623 624 625
dATA_ARRAY_PARALLEL_NAME, dATA_ARRAY_PARALLEL_PRIM_NAME :: ModuleName
dATA_ARRAY_PARALLEL_NAME      = mkModuleNameFS (fsLit "Data.Array.Parallel")
dATA_ARRAY_PARALLEL_PRIM_NAME = mkModuleNameFS (fsLit "Data.Array.Parallel.Prim")

Ian Lynagh's avatar
Ian Lynagh committed
626
mkPrimModule :: FastString -> Module
Sylvain Henry's avatar
Sylvain Henry committed
627
mkPrimModule m = mkModule primUnit (mkModuleNameFS m)
Ian Lynagh's avatar
Ian Lynagh committed
628

Sylvain Henry's avatar
Sylvain Henry committed
629 630
mkBignumModule :: FastString -> Module
mkBignumModule m = mkModule bignumUnit (mkModuleNameFS m)
Ian Lynagh's avatar
Ian Lynagh committed
631

Simon Marlow's avatar
Simon Marlow committed
632
mkBaseModule :: FastString -> Module
Sylvain Henry's avatar
Sylvain Henry committed
633
mkBaseModule m = mkBaseModule_ (mkModuleNameFS m)
Simon Marlow's avatar
Simon Marlow committed
634 635

mkBaseModule_ :: ModuleName -> Module
Sylvain Henry's avatar
Sylvain Henry committed
636
mkBaseModule_ m = mkModule baseUnit m
Simon Marlow's avatar
Simon Marlow committed
637

638
mkThisGhcModule :: FastString -> Module
Sylvain Henry's avatar
Sylvain Henry committed
639
mkThisGhcModule m = mkThisGhcModule_ (mkModuleNameFS m)
640 641

mkThisGhcModule_ :: ModuleName -> Module
Sylvain Henry's avatar
Sylvain Henry committed
642
mkThisGhcModule_ m = mkModule thisGhcUnit m
643

Simon Marlow's avatar
Simon Marlow committed
644
mkMainModule :: FastString -> Module
Sylvain Henry's avatar
Sylvain Henry committed
645
mkMainModule m = mkModule mainUnit (mkModuleNameFS m)
646

Simon Marlow's avatar
Simon Marlow committed
647
mkMainModule_ :: ModuleName -> Module
Sylvain Henry's avatar
Sylvain Henry committed
648
mkMainModule_ m = mkModule mainUnit m
649

Austin Seipp's avatar
Austin Seipp committed
650 651 652
{-
************************************************************************
*                                                                      *
653
                        RdrNames
Austin Seipp's avatar
Austin Seipp committed
654 655 656
*                                                                      *
************************************************************************
-}
657

Ian Lynagh's avatar
Ian Lynagh committed
658
main_RDR_Unqual    :: RdrName
659 660 661
main_RDR_Unqual = mkUnqual varName (fsLit "main")
        -- We definitely don't want an Orig RdrName, because
        -- main might, in principle, be imported into module Main
662

David Feuer's avatar
David Feuer committed
663
eq_RDR, ge_RDR, le_RDR, lt_RDR, gt_RDR, compare_RDR,
Ian Lynagh's avatar
Ian Lynagh committed
664
    ltTag_RDR, eqTag_RDR, gtTag_RDR :: RdrName
665 666 667 668 669 670
eq_RDR                  = nameRdrName eqName
ge_RDR                  = nameRdrName geName
le_RDR                  = varQual_RDR  gHC_CLASSES (fsLit "<=")
lt_RDR                  = varQual_RDR  gHC_CLASSES (fsLit "<")
gt_RDR                  = varQual_RDR  gHC_CLASSES (fsLit ">")
compare_RDR             = varQual_RDR  gHC_CLASSES (fsLit "compare")
671 672 673
ltTag_RDR               = nameRdrName  ordLTDataConName
eqTag_RDR               = nameRdrName  ordEQDataConName
gtTag_RDR               = nameRdrName  ordGTDataConName
674

Ian Lynagh's avatar
Ian Lynagh committed
675 676
eqClass_RDR, numClass_RDR, ordClass_RDR, enumClass_RDR, monadClass_RDR
    :: RdrName
677 678 679 680 681
eqClass_RDR             = nameRdrName eqClassName
numClass_RDR            = nameRdrName numClassName
ordClass_RDR            = nameRdrName ordClassName
enumClass_RDR           = nameRdrName enumClassName
monadClass_RDR          = nameRdrName monadClassName
682

Ian Lynagh's avatar
Ian Lynagh committed
683
map_RDR, append_RDR :: RdrName
684 685
map_RDR                 = nameRdrName mapName
append_RDR              = nameRdrName appendName
686

687 688
foldr_RDR, build_RDR, returnM_RDR, bindM_RDR, failM_RDR
    :: RdrName
689 690 691 692 693
foldr_RDR               = nameRdrName foldrName
build_RDR               = nameRdrName buildName
returnM_RDR             = nameRdrName returnMName
bindM_RDR               = nameRdrName bindMName
failM_RDR               = nameRdrName failMName
694

Ian Lynagh's avatar
Ian Lynagh committed
695
left_RDR, right_RDR :: RdrName
696 697
left_RDR                = nameRdrName leftDataConName
right_RDR               = nameRdrName rightDataConName
698

Ian Lynagh's avatar
Ian Lynagh committed
699
fromEnum_RDR, toEnum_RDR :: RdrName
700 701
fromEnum_RDR            = varQual_RDR gHC_ENUM (fsLit "fromEnum")
toEnum_RDR              = varQual_RDR gHC_ENUM (fsLit "toEnum")
702

Ian Lynagh's avatar
Ian Lynagh committed
703
enumFrom_RDR, enumFromTo_RDR, enumFromThen_RDR, enumFromThenTo_RDR :: RdrName
704 705 706 707
enumFrom_RDR            = nameRdrName enumFromName
enumFromTo_RDR          = nameRdrName enumFromToName
enumFromThen_RDR        = nameRdrName enumFromThenName
enumFromThenTo_RDR      = nameRdrName enumFromThenToName
708

Sylvain Henry's avatar
Sylvain Henry committed
709
ratioDataCon_RDR, integerAdd_RDR, integerMul_RDR :: RdrName
710
ratioDataCon_RDR        = nameRdrName ratioDataConName
Sylvain Henry's avatar
Sylvain Henry committed
711 712
integerAdd_RDR          = nameRdrName integerAddName
integerMul_RDR          = nameRdrName integerMulName
713

Ian Lynagh's avatar
Ian Lynagh committed
714
ioDataCon_RDR :: RdrName
715
ioDataCon_RDR           = nameRdrName ioDataConName
716

Ian Lynagh's avatar
Ian Lynagh committed
717
eqString_RDR, unpackCString_RDR, unpackCStringFoldr_RDR,
Andreas Klebinger's avatar
Andreas Klebinger committed
718
    unpackCStringFoldrUtf8_RDR, unpackCStringUtf8_RDR :: RdrName
719 720 721 722
eqString_RDR            = nameRdrName eqStringName
unpackCString_RDR       = nameRdrName unpackCStringName
unpackCStringFoldr_RDR  = nameRdrName unpackCStringFoldrName
unpackCStringUtf8_RDR   = nameRdrName unpackCStringUtf8Name
Andreas Klebinger's avatar
Andreas Klebinger committed
723
unpackCStringFoldrUtf8_RDR  = nameRdrName unpackCStringFoldrUtf8Name
724

725
newStablePtr_RDR :: RdrName
726
newStablePtr_RDR        = nameRdrName newStablePtrName
727

Ian Lynagh's avatar
Ian Lynagh committed
728
bindIO_RDR, returnIO_RDR :: RdrName
729 730
bindIO_RDR              = nameRdrName bindIOName
returnIO_RDR            = nameRdrName returnIOName
731

Ian Lynagh's avatar
Ian Lynagh committed
732
fromInteger_RDR, fromRational_RDR, minus_RDR, times_RDR, plus_RDR :: RdrName
733 734 735 736
fromInteger_RDR         = nameRdrName fromIntegerName
fromRational_RDR        = nameRdrName fromRationalName
minus_RDR               = nameRdrName minusName
times_RDR               = varQual_RDR  gHC_NUM (fsLit "*")
Ian Lynagh's avatar
Ian Lynagh committed
737
plus_RDR                = varQual_RDR gHC_NUM (fsLit "+")
Simon Marlow's avatar
Simon Marlow committed
738

Ryan Scott's avatar
Ryan Scott committed
739 740 741 742 743
toInteger_RDR, toRational_RDR, fromIntegral_RDR :: RdrName
toInteger_RDR           = nameRdrName toIntegerName
toRational_RDR          = nameRdrName toRationalName
fromIntegral_RDR        = nameRdrName fromIntegralName

Simon Peyton Jones's avatar
Simon Peyton Jones committed
744
fromString_RDR :: RdrName
745
fromString_RDR          = nameRdrName fromStringName
746

747 748 749 750 751
fromList_RDR, fromListN_RDR, toList_RDR :: RdrName
fromList_RDR = nameRdrName fromListName
fromListN_RDR = nameRdrName fromListNName
toList_RDR = nameRdrName toListName

Ian Lynagh's avatar
Ian Lynagh committed
752
compose_RDR :: RdrName
753
compose_RDR             = varQual_RDR gHC_BASE (fsLit ".")
Simon Marlow's avatar
Simon Marlow committed
754

Ian Lynagh's avatar
Ian Lynagh committed
755
not_RDR, getTag_RDR, succ_RDR, pred_RDR, minBound_RDR, maxBound_RDR,
756
    and_RDR, range_RDR, inRange_RDR, index_RDR,
Ian Lynagh's avatar
Ian Lynagh committed
757
    unsafeIndex_RDR, unsafeRangeSize_RDR :: RdrName
758 759 760 761
and_RDR                 = varQual_RDR gHC_CLASSES (fsLit "&&")
not_RDR                 = varQual_RDR gHC_CLASSES (fsLit "not")
getTag_RDR              = varQual_RDR gHC_BASE (fsLit "getTag")
succ_RDR                = varQual_RDR gHC_ENUM (fsLit "succ")
Ian Lynagh's avatar
Ian Lynagh committed
762 763 764
pred_RDR                = varQual_RDR gHC_ENUM (fsLit "pred")
minBound_RDR            = varQual_RDR gHC_ENUM (fsLit "minBound")
maxBound_RDR            = varQual_RDR gHC_ENUM (fsLit "maxBound")
Ben Gamari's avatar
Ben Gamari committed
765 766 767 768 769
range_RDR               = varQual_RDR gHC_IX (fsLit "range")
inRange_RDR             = varQual_RDR gHC_IX (fsLit "inRange")
index_RDR               = varQual_RDR gHC_IX (fsLit "index")
unsafeIndex_RDR         = varQual_RDR gHC_IX (fsLit "unsafeIndex")
unsafeRangeSize_RDR     = varQual_RDR gHC_IX (fsLit "unsafeRangeSize")
Simon Marlow's avatar
Simon Marlow committed
770

Ian Lynagh's avatar
Ian Lynagh committed
771
readList_RDR, readListDefault_RDR, readListPrec_RDR, readListPrecDefault_RDR,
772
    readPrec_RDR, parens_RDR, choose_RDR, lexP_RDR, expectP_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
773 774 775 776 777 778 779 780
readList_RDR            = varQual_RDR gHC_READ (fsLit "readList")
readListDefault_RDR     = varQual_RDR gHC_READ (fsLit "readListDefault")
readListPrec_RDR        = varQual_RDR gHC_READ (fsLit "readListPrec")
readListPrecDefault_RDR = varQual_RDR gHC_READ (fsLit "readListPrecDefault")
readPrec_RDR            = varQual_RDR gHC_READ (fsLit "readPrec")
parens_RDR              = varQual_RDR gHC_READ (fsLit "parens")
choose_RDR              = varQual_RDR gHC_READ (fsLit "choose")
lexP_RDR                = varQual_RDR gHC_READ (fsLit "lexP")
781
expectP_RDR             = varQual_RDR gHC_READ (fsLit "expectP")
782

783
readField_RDR, readFieldHash_RDR, readSymField_RDR :: RdrName
Tobias Dammers's avatar
Tobias Dammers committed
784
readField_RDR           = varQual_RDR gHC_READ (fsLit "readField")
785
readFieldHash_RDR       = varQual_RDR gHC_READ (fsLit "readFieldHash")
Tobias Dammers's avatar
Tobias Dammers committed
786 787
readSymField_RDR        = varQual_RDR gHC_READ (fsLit "readSymField")

Ian Lynagh's avatar
Ian Lynagh committed
788
punc_RDR, ident_RDR, symbol_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
789 790 791
punc_RDR                = dataQual_RDR lEX (fsLit "Punc")
ident_RDR               = dataQual_RDR lEX (fsLit "Ident")
symbol_RDR              = dataQual_RDR lEX (fsLit "Symbol")
792

793
step_RDR, alt_RDR, reset_RDR, prec_RDR, pfail_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
794
step_RDR                = varQual_RDR  rEAD_PREC (fsLit "step")
795
alt_RDR                 = varQual_RDR  rEAD_PREC (fsLit "+++")
Ian Lynagh's avatar
Ian Lynagh committed
796 797
reset_RDR               = varQual_RDR  rEAD_PREC (fsLit "reset")
prec_RDR                = varQual_RDR  rEAD_PREC (fsLit "prec")
798
pfail_RDR               = varQual_RDR  rEAD_PREC (fsLit "pfail")
799

David Feuer's avatar
David Feuer committed
800
showsPrec_RDR, shows_RDR, showString_RDR,
Ben Gamari's avatar
Ben Gamari committed
801
    showSpace_RDR, showCommaSpace_RDR, showParen_RDR :: RdrName
802
showsPrec_RDR           = varQual_RDR gHC_SHOW (fsLit "showsPrec")
thomie's avatar
thomie committed
803
shows_RDR               = varQual_RDR gHC_SHOW (fsLit "shows")
Ian Lynagh's avatar
Ian Lynagh committed
804
showString_RDR          = varQual_RDR gHC_SHOW (fsLit "showString")
805
showSpace_RDR           = varQual_RDR gHC_SHOW (fsLit "showSpace")
Ben Gamari's avatar
Ben Gamari committed
806
showCommaSpace_RDR      = varQual_RDR gHC_SHOW (fsLit "showCommaSpace")
807
showParen_RDR           = varQual_RDR gHC_SHOW (fsLit "showParen")
808

809 810 811 812 813 814
error_RDR :: RdrName
error_RDR = varQual_RDR gHC_ERR (fsLit "error")

-- Generics (constructors and functions)
u1DataCon_RDR, par1DataCon_RDR, rec1DataCon_RDR,
  k1DataCon_RDR, m1DataCon_RDR, l1DataCon_RDR, r1DataCon_RDR,
jpm@cs.ox.ac.uk's avatar
jpm@cs.ox.ac.uk committed
815 816 817
  prodDataCon_RDR, comp1DataCon_RDR,
  unPar1_RDR, unRec1_RDR, unK1_RDR, unComp1_RDR,
  from_RDR, from1_RDR, to_RDR, to1_RDR,
818
  datatypeName_RDR, moduleName_RDR, packageName_RDR, isNewtypeName_RDR,
819
  conName_RDR, conFixity_RDR, conIsRecord_RDR, selName_RDR,