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

4 5 6
\section[PrelNames]{Definitions of prelude modules and names}


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
Thomas Schilling's avatar
Thomas Schilling committed
27 28 29 30 31
   The may way the compiler "knows about" one of these things is
   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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  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
     TysWiredIn) are used to initialise the "OrigNameCache" in
     IfaceEnv.  This initialization ensures that when the type checker
     or renamer (both of which use IfaceEnv) look up an original name
     (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.

  3. For "infinite families" of known-key names (i.e. tuples), we have
     to be extra careful. Because there are an infinite number of
     these things, we cannot add them to the list of known-key names
     used to initialise the OrigNameCache. Instead, we have to
     rely on never having to look them up in that cache.
81

82
     This is accomplished through a variety of mechanisms:
83

84
       a) The parser recognises them specially and generates an
85
          Exact Name (hence not looked up in the orig-name cache)
86

87 88 89 90
       b) The known infinite families of names are specially
          serialised by BinIface.putName, with that special treatment
          detected when we read back to ensure that we get back to the
          correct uniques.
91

92 93 94 95 96
       Most of the infinite families cannot occur in source code,
       so mechanisms (a,b) sufficies 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.
97

98 99 100
       c) IfaceEnv.lookupOrigNameCache uses isBuiltInOcc_maybe to map
          built-in syntax directly onto the corresponding name, rather
          than trying to find it in the original-name cache.
101

102
          See also Note [Built-in syntax and the OrigNameCache]
Austin Seipp's avatar
Austin Seipp committed
103
-}
104

105 106
{-# LANGUAGE CPP #-}

107
module PrelNames (
108 109 110 111 112 113 114 115
        Unique, Uniquable(..), hasKey,  -- Re-exported for convenience

        -----------------------------------------------------------
        module PrelNames,       -- 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
116
    ) where
117 118 119

#include "HsVersions.h"

120
import Module
Ian Lynagh's avatar
Ian Lynagh committed
121
import OccName
122 123 124
import RdrName
import Unique
import Name
125
import SrcLoc
126
import FastString
127 128
import Config ( cIntegerLibraryType, IntegerLibrary(..) )
import Panic ( panic )
129

Austin Seipp's avatar
Austin Seipp committed
130 131 132
{-
************************************************************************
*                                                                      *
133
     allNameStrings
Austin Seipp's avatar
Austin Seipp committed
134 135 136
*                                                                      *
************************************************************************
-}
137 138 139

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

Austin Seipp's avatar
Austin Seipp committed
142 143 144
{-
************************************************************************
*                                                                      *
145
\subsection{Local Names}
Austin Seipp's avatar
Austin Seipp committed
146 147
*                                                                      *
************************************************************************
148 149

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

152 153
itName :: Unique -> SrcSpan -> Name
itName uniq loc = mkInternalName uniq (mkOccNameFS varName (fsLit "it")) loc
154 155 156

-- mkUnboundName makes a place-holder Name; it shouldn't be looked at except possibly
-- during compiler debugging.
157 158
mkUnboundName :: OccName -> Name
mkUnboundName occ = mkInternalName unboundKey occ noSrcSpan
159 160 161 162

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

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

170
This section tells what the compiler knows about the association of
171 172
names with uniques.  These ones are the *non* wired-in ones.  The
wired in ones are defined in TysWiredIn etc.
Austin Seipp's avatar
Austin Seipp committed
173
-}
174

175 176
basicKnownKeyNames :: [Name]
basicKnownKeyNames
177
 = genericTyConNames
Ben Gamari's avatar
Ben Gamari committed
178
 ++ [   --  Classes.  *Must* include:
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
        --      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,
197
        alternativeClassName,
198 199
        foldableClassName,
        traversableClassName,
200 201
        semigroupClassName, sappendName,
        monoidClassName, memptyName, mappendName, mconcatName,
202

Ben Gamari's avatar
Ben Gamari committed
203 204 205 206 207
        -- The IO type
        -- See Note [TyConRepNames for non-wired-in TyCons]
        ioTyConName, ioDataConName,
        runMainIOName,

208 209 210
        -- Typeable
        typeableClassName,
        typeRepTyConName,
211 212 213 214
        trTyConDataConName,
        trModuleDataConName,
        trNameSDataConName,
        typeRepIdName,
215 216
        mkPolyTyConAppName,
        mkAppTyName,
217
        typeSymbolTypeRepName, typeNatTypeRepName,
218

219 220
        -- Dynamic
        toDynName,
221 222

        -- Numeric stuff
223 224 225
        negateName, minusName, geName, eqName,

        -- Conversion functions
Ben Gamari's avatar
Ben Gamari committed
226 227
        rationalTyConName,
        ratioTyConName, ratioDataConName,
228 229 230
        fromRationalName, fromIntegerName,
        toIntegerName, toRationalName,
        fromIntegralName, realToFracName,
231 232 233

        -- String stuff
        fromStringName,
234 235 236 237 238

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

239 240
        -- Applicative stuff
        pureAName, apAName, thenAName,
241

242
        -- Monad stuff
quchen's avatar
quchen committed
243 244 245 246 247
        thenIOName, bindIOName, returnIOName, failIOName, bindMName, thenMName,
        returnMName, fmapName, joinMName,

        -- MonadFail
        monadFailClassName, failMName, failMName_preMFP,
248

249 250
        -- MonadFix
        monadFixClassName, mfixName,
251

252 253 254
        -- Arrow stuff
        arrAName, composeAName, firstAName,
        appAName, choiceAName, loopAName,
255

256 257
        -- Ix stuff
        ixClassName,
258

259 260
        -- Show stuff
        showClassName,
261

262 263
        -- Read stuff
        readClassName,
264

265 266
        -- Stable pointers
        newStablePtrName,
267

268
        -- GHC Extensions
269
        groupWithName,
270

271 272 273
        -- Strings and lists
        unpackCStringName,
        unpackCStringFoldrName, unpackCStringUtf8Name,
274

275 276 277 278 279
        -- Overloaded lists
        isListClassName,
        fromListName,
        fromListNName,
        toListName,
280

281 282 283
        -- List operations
        concatName, filterName, mapName,
        zipName, foldrName, buildName, augmentName, appendName,
284

285 286 287
        -- FFI primitive types that are not wired-in.
        stablePtrTyConName, ptrTyConName, funPtrTyConName,
        int8TyConName, int16TyConName, int32TyConName, int64TyConName,
288
        word16TyConName, word32TyConName, word64TyConName,
289

290 291 292
        -- Others
        otherwiseIdName, inlineIdName,
        eqStringName, assertName, breakpointName, breakpointCondName,
293
        breakpointAutoName,  opaqueTyConName,
rwbarton's avatar
rwbarton committed
294
        assertErrorName,
295
        printName, fstName, sndName,
296

297
        -- Integer
298
        integerTyConName, mkIntegerName,
299
        integerToWord64Name, integerToInt64Name,
Ian Lynagh's avatar
Ian Lynagh committed
300
        word64ToIntegerName, int64ToIntegerName,
301
        plusIntegerName, timesIntegerName, smallIntegerName,
302
        wordToIntegerName,
303
        integerToWordName, integerToIntName, minusIntegerName,
304
        negateIntegerName, eqIntegerPrimName, neqIntegerPrimName,
305
        absIntegerName, signumIntegerName,
306
        leIntegerPrimName, gtIntegerPrimName, ltIntegerPrimName, geIntegerPrimName,
Ian Lynagh's avatar
Ian Lynagh committed
307
        compareIntegerName, quotRemIntegerName, divModIntegerName,
308
        quotIntegerName, remIntegerName, divIntegerName, modIntegerName,
309
        floatFromIntegerName, doubleFromIntegerName,
310
        encodeFloatIntegerName, encodeDoubleIntegerName,
Ian Lynagh's avatar
Ian Lynagh committed
311
        decodeDoubleIntegerName,
312 313
        gcdIntegerName, lcmIntegerName,
        andIntegerName, orIntegerName, xorIntegerName, complementIntegerName,
314
        shiftLIntegerName, shiftRIntegerName, bitIntegerName,
315

316 317 318 319
        -- Float/Double
        rationalToFloatName,
        rationalToDoubleName,

320 321
        -- Other classes
        randomClassName, randomGenClassName, monadPlusClassName,
322

323
        -- Type-level naturals
324
        knownNatClassName, knownSymbolClassName,
325

Adam Gundry's avatar
Adam Gundry committed
326 327 328
        -- Overloaded labels
        isLabelClassName,

329 330 331 332
        -- Source locations
        callStackDataConName, callStackTyConName,
        srcLocDataConName,

333
        -- Annotation type checking
334
        toAnnotationWrapperName
335

336
        -- The Ordering type
Ben Gamari's avatar
Ben Gamari committed
337 338
        , orderingTyConName
        , ltDataConName, eqDataConName, gtDataConName
339

340 341 342
        -- The SPEC type for SpecConstr
        , specTyConName

343 344
        -- The Either type
        , eitherTyConName, leftDataConName, rightDataConName
345

346 347
        -- Plugins
        , pluginTyConName
Edward Z. Yang's avatar
Edward Z. Yang committed
348
        , frontendPluginTyConName
349 350 351 352 353

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

354 355 356 357
        -- Monad comprehensions
        , guardMName
        , liftMName
        , mzipName
dterei's avatar
dterei committed
358 359 360

        -- GHCi Sandbox
        , ghciIoClassName, ghciStepIoMName
Facundo Domínguez's avatar
Facundo Domínguez committed
361 362 363 364 365 366 367 368

        -- StaticPtr
        , staticPtrTyConName
        , staticPtrDataConName, staticPtrInfoDataConName

        -- Fingerprint
        , fingerprintDataConName

369 370 371 372 373 374 375
        -- Custom type errors
        , errorMessageTypeErrorFamName
        , typeErrorTextDataConName
        , typeErrorAppendDataConName
        , typeErrorVAppendDataConName
        , typeErrorShowTypeDataConName

376 377 378
        -- homogeneous equality
        , eqTyConName

379 380 381
    ] ++ case cIntegerLibraryType of
           IntegerGMP    -> [integerSDataConName]
           IntegerSimple -> []
382

383
genericTyConNames :: [Name]
384 385 386
genericTyConNames = [
    v1TyConName, u1TyConName, par1TyConName, rec1TyConName,
    k1TyConName, m1TyConName, sumTyConName, prodTyConName,
387 388
    compTyConName, rTyConName, dTyConName,
    cTyConName, sTyConName, rec0TyConName,
389
    d1TyConName, c1TyConName, s1TyConName, noSelTyConName,
390 391
    repTyConName, rep1TyConName, uRecTyConName,
    uAddrTyConName, uCharTyConName, uDoubleTyConName,
392 393 394
    uFloatTyConName, uIntTyConName, uWordTyConName,
    prefixIDataConName, infixIDataConName, leftAssociativeDataConName,
    rightAssociativeDataConName, notAssociativeDataConName,
395 396 397 398 399
    sourceUnpackDataConName, sourceNoUnpackDataConName,
    noSourceUnpackednessDataConName, sourceLazyDataConName,
    sourceStrictDataConName, noSourceStrictnessDataConName,
    decidedLazyDataConName, decidedStrictDataConName, decidedUnpackDataConName,
    metaDataDataConName, metaConsDataConName, metaSelDataConName
400
  ]
401

Austin Seipp's avatar
Austin Seipp committed
402 403 404
{-
************************************************************************
*                                                                      *
405
\subsection{Module names}
Austin Seipp's avatar
Austin Seipp committed
406 407
*                                                                      *
************************************************************************
408

409 410

--MetaHaskell Extension Add a new module here
Austin Seipp's avatar
Austin Seipp committed
411 412
-}

Ian Lynagh's avatar
Ian Lynagh committed
413
pRELUDE :: Module
414
pRELUDE         = mkBaseModule_ pRELUDE_NAME
Ian Lynagh's avatar
Ian Lynagh committed
415

Joachim Breitner's avatar
Joachim Breitner committed
416
gHC_PRIM, gHC_TYPES, gHC_GENERICS, gHC_MAGIC,
dterei's avatar
dterei committed
417
    gHC_CLASSES, gHC_BASE, gHC_ENUM, gHC_GHCI, gHC_CSTRING,
418
    gHC_SHOW, gHC_READ, gHC_NUM, gHC_INTEGER_TYPE, gHC_LIST,
419 420
    gHC_TUPLE, dATA_TUPLE, dATA_EITHER, dATA_STRING,
    dATA_FOLDABLE, dATA_TRAVERSABLE, dATA_MONOID, dATA_SEMIGROUP,
dterei's avatar
dterei committed
421 422
    gHC_CONC, gHC_IO, gHC_IO_Exception,
    gHC_ST, gHC_ARR, gHC_STABLE, gHC_PTR, gHC_ERR, gHC_REAL,
423
    gHC_FLOAT, gHC_TOP_HANDLER, sYSTEM_IO, dYNAMIC,
424
    tYPEABLE, tYPEABLE_INTERNAL, gENERICS,
quchen's avatar
quchen committed
425
    rEAD_PREC, lEX, gHC_INT, gHC_WORD, mONAD, mONAD_FIX, mONAD_ZIP, mONAD_FAIL,
426
    aRROW, cONTROL_APPLICATIVE, gHC_DESUGAR, rANDOM, gHC_EXTS,
427 428
    cONTROL_EXCEPTION_BASE, gHC_TYPELITS, dATA_TYPE_EQUALITY,
    dATA_COERCE :: Module
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
429

430
gHC_PRIM        = mkPrimModule (fsLit "GHC.Prim")   -- Primitive types and values
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
431
gHC_TYPES       = mkPrimModule (fsLit "GHC.Types")
432 433 434 435 436 437
gHC_MAGIC       = mkPrimModule (fsLit "GHC.Magic")
gHC_CSTRING     = mkPrimModule (fsLit "GHC.CString")
gHC_CLASSES     = mkPrimModule (fsLit "GHC.Classes")

gHC_BASE        = mkBaseModule (fsLit "GHC.Base")
gHC_ENUM        = mkBaseModule (fsLit "GHC.Enum")
dterei's avatar
dterei committed
438
gHC_GHCI        = mkBaseModule (fsLit "GHC.GHCi")
439 440 441
gHC_SHOW        = mkBaseModule (fsLit "GHC.Show")
gHC_READ        = mkBaseModule (fsLit "GHC.Read")
gHC_NUM         = mkBaseModule (fsLit "GHC.Num")
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
442
gHC_INTEGER_TYPE= mkIntegerModule (fsLit "GHC.Integer.Type")
443 444 445
gHC_LIST        = mkBaseModule (fsLit "GHC.List")
gHC_TUPLE       = mkPrimModule (fsLit "GHC.Tuple")
dATA_TUPLE      = mkBaseModule (fsLit "Data.Tuple")
446 447 448
dATA_EITHER     = mkBaseModule (fsLit "Data.Either")
dATA_STRING     = mkBaseModule (fsLit "Data.String")
dATA_FOLDABLE   = mkBaseModule (fsLit "Data.Foldable")
449
dATA_TRAVERSABLE= mkBaseModule (fsLit "Data.Traversable")
450
dATA_SEMIGROUP  = mkBaseModule (fsLit "Data.Semigroup")
451
dATA_MONOID     = mkBaseModule (fsLit "Data.Monoid")
452 453
gHC_CONC        = mkBaseModule (fsLit "GHC.Conc")
gHC_IO          = mkBaseModule (fsLit "GHC.IO")
454
gHC_IO_Exception = mkBaseModule (fsLit "GHC.IO.Exception")
455 456 457 458 459 460 461 462 463 464
gHC_ST          = mkBaseModule (fsLit "GHC.ST")
gHC_ARR         = mkBaseModule (fsLit "GHC.Arr")
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")
465 466
tYPEABLE        = mkBaseModule (fsLit "Data.Typeable")
tYPEABLE_INTERNAL = mkBaseModule (fsLit "Data.Typeable.Internal")
467
gENERICS        = mkBaseModule (fsLit "Data.Data")
468 469 470 471 472 473
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")
474
mONAD_ZIP       = mkBaseModule (fsLit "Control.Monad.Zip")
quchen's avatar
quchen committed
475
mONAD_FAIL      = mkBaseModule (fsLit "Control.Monad.Fail")
476
aRROW           = mkBaseModule (fsLit "Control.Arrow")
477
cONTROL_APPLICATIVE = mkBaseModule (fsLit "Control.Applicative")
Ian Lynagh's avatar
Ian Lynagh committed
478
gHC_DESUGAR = mkBaseModule (fsLit "GHC.Desugar")
479 480
rANDOM          = mkBaseModule (fsLit "System.Random")
gHC_EXTS        = mkBaseModule (fsLit "GHC.Exts")
481
cONTROL_EXCEPTION_BASE = mkBaseModule (fsLit "Control.Exception.Base")
jpm@cs.ox.ac.uk's avatar
jpm@cs.ox.ac.uk committed
482
gHC_GENERICS    = mkBaseModule (fsLit "GHC.Generics")
483
gHC_TYPELITS    = mkBaseModule (fsLit "GHC.TypeLits")
484 485
dATA_TYPE_EQUALITY = mkBaseModule (fsLit "Data.Type.Equality")
dATA_COERCE     = mkBaseModule (fsLit "Data.Coerce")
Simon Marlow's avatar
Simon Marlow committed
486

487 488 489
gHC_PARR' :: Module
gHC_PARR' = mkBaseModule (fsLit "GHC.PArr")

490 491 492
gHC_SRCLOC :: Module
gHC_SRCLOC = mkBaseModule (fsLit "GHC.SrcLoc")

Ben Gamari's avatar
Ben Gamari committed
493
gHC_STACK, gHC_STACK_TYPES :: Module
494
gHC_STACK = mkBaseModule (fsLit "GHC.Stack")
Ben Gamari's avatar
Ben Gamari committed
495
gHC_STACK_TYPES = mkBaseModule (fsLit "GHC.Stack.Types")
496

Facundo Domínguez's avatar
Facundo Domínguez committed
497 498 499 500 501 502
gHC_STATICPTR :: Module
gHC_STATICPTR = mkBaseModule (fsLit "GHC.StaticPtr")

gHC_FINGERPRINT_TYPE :: Module
gHC_FINGERPRINT_TYPE = mkBaseModule (fsLit "GHC.Fingerprint.Type")

Adam Gundry's avatar
Adam Gundry committed
503 504 505
gHC_OVER_LABELS :: Module
gHC_OVER_LABELS = mkBaseModule (fsLit "GHC.OverloadedLabels")

Ian Lynagh's avatar
Ian Lynagh committed
506
mAIN, rOOT_MAIN :: Module
507 508
mAIN            = mkMainModule_ mAIN_NAME
rOOT_MAIN       = mkMainModule (fsLit ":Main") -- Root module for initialisation
Simon Marlow's avatar
Simon Marlow committed
509

510 511
mkInteractiveModule :: Int -> Module
-- (mkInteractiveMoudule 9) makes module 'interactive:M9'
512
mkInteractiveModule n = mkModule interactiveUnitId (mkModuleName ("Ghci" ++ show n))
Simon Marlow's avatar
Simon Marlow committed
513

Ian Lynagh's avatar
Ian Lynagh committed
514
pRELUDE_NAME, mAIN_NAME :: ModuleName
Ian Lynagh's avatar
Ian Lynagh committed
515 516
pRELUDE_NAME   = mkModuleNameFS (fsLit "Prelude")
mAIN_NAME      = mkModuleNameFS (fsLit "Main")
Simon Marlow's avatar
Simon Marlow committed
517

518 519 520 521
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
522
mkPrimModule :: FastString -> Module
523
mkPrimModule m = mkModule primUnitId (mkModuleNameFS m)
Ian Lynagh's avatar
Ian Lynagh committed
524 525

mkIntegerModule :: FastString -> Module
526
mkIntegerModule m = mkModule integerUnitId (mkModuleNameFS m)
Ian Lynagh's avatar
Ian Lynagh committed
527

Simon Marlow's avatar
Simon Marlow committed
528
mkBaseModule :: FastString -> Module
529
mkBaseModule m = mkModule baseUnitId (mkModuleNameFS m)
Simon Marlow's avatar
Simon Marlow committed
530 531

mkBaseModule_ :: ModuleName -> Module
532
mkBaseModule_ m = mkModule baseUnitId m
Simon Marlow's avatar
Simon Marlow committed
533

534
mkThisGhcModule :: FastString -> Module
535
mkThisGhcModule m = mkModule thisGhcUnitId (mkModuleNameFS m)
536 537

mkThisGhcModule_ :: ModuleName -> Module
538
mkThisGhcModule_ m = mkModule thisGhcUnitId m
539

Simon Marlow's avatar
Simon Marlow committed
540
mkMainModule :: FastString -> Module
541
mkMainModule m = mkModule mainUnitId (mkModuleNameFS m)
542

Simon Marlow's avatar
Simon Marlow committed
543
mkMainModule_ :: ModuleName -> Module
544
mkMainModule_ m = mkModule mainUnitId m
545

Austin Seipp's avatar
Austin Seipp committed
546 547 548
{-
************************************************************************
*                                                                      *
549
                        RdrNames
Austin Seipp's avatar
Austin Seipp committed
550 551 552
*                                                                      *
************************************************************************
-}
553

Ian Lynagh's avatar
Ian Lynagh committed
554
main_RDR_Unqual    :: RdrName
555 556 557
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
558

559
forall_tv_RDR, dot_tv_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
560 561
forall_tv_RDR = mkUnqual tvName (fsLit "forall")
dot_tv_RDR    = mkUnqual tvName (fsLit ".")
562

Ian Lynagh's avatar
Ian Lynagh committed
563 564
eq_RDR, ge_RDR, ne_RDR, le_RDR, lt_RDR, gt_RDR, compare_RDR,
    ltTag_RDR, eqTag_RDR, gtTag_RDR :: RdrName
565 566 567 568 569 570 571
eq_RDR                  = nameRdrName eqName
ge_RDR                  = nameRdrName geName
ne_RDR                  = varQual_RDR  gHC_CLASSES (fsLit "/=")
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")
Ian Lynagh's avatar
Ian Lynagh committed
572 573 574
ltTag_RDR               = dataQual_RDR gHC_TYPES (fsLit "LT")
eqTag_RDR               = dataQual_RDR gHC_TYPES (fsLit "EQ")
gtTag_RDR               = dataQual_RDR gHC_TYPES (fsLit "GT")
575

Ian Lynagh's avatar
Ian Lynagh committed
576 577
eqClass_RDR, numClass_RDR, ordClass_RDR, enumClass_RDR, monadClass_RDR
    :: RdrName
578 579 580 581 582
eqClass_RDR             = nameRdrName eqClassName
numClass_RDR            = nameRdrName numClassName
ordClass_RDR            = nameRdrName ordClassName
enumClass_RDR           = nameRdrName enumClassName
monadClass_RDR          = nameRdrName monadClassName
583

Ian Lynagh's avatar
Ian Lynagh committed
584
map_RDR, append_RDR :: RdrName
585 586
map_RDR                 = varQual_RDR gHC_BASE (fsLit "map")
append_RDR              = varQual_RDR gHC_BASE (fsLit "++")
587

quchen's avatar
quchen committed
588
foldr_RDR, build_RDR, returnM_RDR, bindM_RDR, failM_RDR_preMFP, failM_RDR:: RdrName
589 590 591 592
foldr_RDR               = nameRdrName foldrName
build_RDR               = nameRdrName buildName
returnM_RDR             = nameRdrName returnMName
bindM_RDR               = nameRdrName bindMName
quchen's avatar
quchen committed
593
failM_RDR_preMFP        = nameRdrName failMName_preMFP
594
failM_RDR               = nameRdrName failMName
595

Ian Lynagh's avatar
Ian Lynagh committed
596
left_RDR, right_RDR :: RdrName
597 598
left_RDR                = nameRdrName leftDataConName
right_RDR               = nameRdrName rightDataConName
599

Ian Lynagh's avatar
Ian Lynagh committed
600
fromEnum_RDR, toEnum_RDR :: RdrName
601 602
fromEnum_RDR            = varQual_RDR gHC_ENUM (fsLit "fromEnum")
toEnum_RDR              = varQual_RDR gHC_ENUM (fsLit "toEnum")
603

Ian Lynagh's avatar
Ian Lynagh committed
604
enumFrom_RDR, enumFromTo_RDR, enumFromThen_RDR, enumFromThenTo_RDR :: RdrName
605 606 607 608
enumFrom_RDR            = nameRdrName enumFromName
enumFromTo_RDR          = nameRdrName enumFromToName
enumFromThen_RDR        = nameRdrName enumFromThenName
enumFromThenTo_RDR      = nameRdrName enumFromThenToName
609

Ian Lynagh's avatar
Ian Lynagh committed
610
ratioDataCon_RDR, plusInteger_RDR, timesInteger_RDR :: RdrName
611 612 613
ratioDataCon_RDR        = nameRdrName ratioDataConName
plusInteger_RDR         = nameRdrName plusIntegerName
timesInteger_RDR        = nameRdrName timesIntegerName
614

Ian Lynagh's avatar
Ian Lynagh committed
615
ioDataCon_RDR :: RdrName
616
ioDataCon_RDR           = nameRdrName ioDataConName
617

Ian Lynagh's avatar
Ian Lynagh committed
618 619
eqString_RDR, unpackCString_RDR, unpackCStringFoldr_RDR,
    unpackCStringUtf8_RDR :: RdrName
620 621 622 623
eqString_RDR            = nameRdrName eqStringName
unpackCString_RDR       = nameRdrName unpackCStringName
unpackCStringFoldr_RDR  = nameRdrName unpackCStringFoldrName
unpackCStringUtf8_RDR   = nameRdrName unpackCStringUtf8Name
624

625
newStablePtr_RDR :: RdrName
626
newStablePtr_RDR        = nameRdrName newStablePtrName
627

Ian Lynagh's avatar
Ian Lynagh committed
628
bindIO_RDR, returnIO_RDR :: RdrName
629 630
bindIO_RDR              = nameRdrName bindIOName
returnIO_RDR            = nameRdrName returnIOName
631

Ian Lynagh's avatar
Ian Lynagh committed
632
fromInteger_RDR, fromRational_RDR, minus_RDR, times_RDR, plus_RDR :: RdrName
633 634 635 636
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
637
plus_RDR                = varQual_RDR gHC_NUM (fsLit "+")
Simon Marlow's avatar
Simon Marlow committed
638

Ryan Scott's avatar
Ryan Scott committed
639 640 641 642 643
toInteger_RDR, toRational_RDR, fromIntegral_RDR :: RdrName
toInteger_RDR           = nameRdrName toIntegerName
toRational_RDR          = nameRdrName toRationalName
fromIntegral_RDR        = nameRdrName fromIntegralName

644 645
stringTy_RDR, fromString_RDR :: RdrName
stringTy_RDR            = tcQual_RDR gHC_BASE (fsLit "String")
646
fromString_RDR          = nameRdrName fromStringName
647

648 649 650 651 652
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
653
compose_RDR :: RdrName
654
compose_RDR             = varQual_RDR gHC_BASE (fsLit ".")
Simon Marlow's avatar
Simon Marlow committed
655

Ian Lynagh's avatar
Ian Lynagh committed
656
not_RDR, getTag_RDR, succ_RDR, pred_RDR, minBound_RDR, maxBound_RDR,
657
    and_RDR, range_RDR, inRange_RDR, index_RDR,
Ian Lynagh's avatar
Ian Lynagh committed
658
    unsafeIndex_RDR, unsafeRangeSize_RDR :: RdrName
659 660 661 662
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
663 664 665 666 667
pred_RDR                = varQual_RDR gHC_ENUM (fsLit "pred")
minBound_RDR            = varQual_RDR gHC_ENUM (fsLit "minBound")
maxBound_RDR            = varQual_RDR gHC_ENUM (fsLit "maxBound")
range_RDR               = varQual_RDR gHC_ARR (fsLit "range")
inRange_RDR             = varQual_RDR gHC_ARR (fsLit "inRange")
668 669 670
index_RDR               = varQual_RDR gHC_ARR (fsLit "index")
unsafeIndex_RDR         = varQual_RDR gHC_ARR (fsLit "unsafeIndex")
unsafeRangeSize_RDR     = varQual_RDR gHC_ARR (fsLit "unsafeRangeSize")
Simon Marlow's avatar
Simon Marlow committed
671

Ian Lynagh's avatar
Ian Lynagh committed
672
readList_RDR, readListDefault_RDR, readListPrec_RDR, readListPrecDefault_RDR,
673
    readPrec_RDR, parens_RDR, choose_RDR, lexP_RDR, expectP_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
674 675 676 677 678 679 680 681
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")
682
expectP_RDR             = varQual_RDR gHC_READ (fsLit "expectP")
683

Ian Lynagh's avatar
Ian Lynagh committed
684
punc_RDR, ident_RDR, symbol_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
685 686 687
punc_RDR                = dataQual_RDR lEX (fsLit "Punc")
ident_RDR               = dataQual_RDR lEX (fsLit "Ident")
symbol_RDR              = dataQual_RDR lEX (fsLit "Symbol")
688

689
step_RDR, alt_RDR, reset_RDR, prec_RDR, pfail_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
690
step_RDR                = varQual_RDR  rEAD_PREC (fsLit "step")
691
alt_RDR                 = varQual_RDR  rEAD_PREC (fsLit "+++")
Ian Lynagh's avatar
Ian Lynagh committed
692 693
reset_RDR               = varQual_RDR  rEAD_PREC (fsLit "reset")
prec_RDR                = varQual_RDR  rEAD_PREC (fsLit "prec")
694
pfail_RDR               = varQual_RDR  rEAD_PREC (fsLit "pfail")
695

thomie's avatar
thomie committed
696
showList_RDR, showList___RDR, showsPrec_RDR, shows_RDR, showString_RDR,
Ian Lynagh's avatar
Ian Lynagh committed
697
    showSpace_RDR, showParen_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
698 699
showList_RDR            = varQual_RDR gHC_SHOW (fsLit "showList")
showList___RDR          = varQual_RDR gHC_SHOW (fsLit "showList__")
700
showsPrec_RDR           = varQual_RDR gHC_SHOW (fsLit "showsPrec")
thomie's avatar
thomie committed
701
shows_RDR               = varQual_RDR gHC_SHOW (fsLit "shows")
Ian Lynagh's avatar
Ian Lynagh committed
702
showString_RDR          = varQual_RDR gHC_SHOW (fsLit "showString")
703 704
showSpace_RDR           = varQual_RDR gHC_SHOW (fsLit "showSpace")
showParen_RDR           = varQual_RDR gHC_SHOW (fsLit "showParen")
705

Ian Lynagh's avatar
Ian Lynagh committed
706
undefined_RDR :: RdrName
Ian Lynagh's avatar
Ian Lynagh committed
707
undefined_RDR = varQual_RDR gHC_ERR (fsLit "undefined")
708

709 710 711 712 713 714
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
715 716 717
  prodDataCon_RDR, comp1DataCon_RDR,
  unPar1_RDR, unRec1_RDR, unK1_RDR, unComp1_RDR,
  from_RDR, from1_RDR, to_RDR, to1_RDR,
718
  datatypeName_RDR, moduleName_RDR, packageName_RDR, isNewtypeName_RDR,
719
  conName_RDR, conFixity_RDR, conIsRecord_RDR, selName_RDR,
720
  prefixDataCon_RDR, infixDataCon_RDR, leftAssocDataCon_RDR,
721 722 723 724 725
  rightAssocDataCon_RDR, notAssocDataCon_RDR,
  uAddrDataCon_RDR, uCharDataCon_RDR, uDoubleDataCon_RDR,
  uFloatDataCon_RDR, uIntDataCon_RDR, uWordDataCon_RDR,
  uAddrHash_RDR, uCharHash_RDR, uDoubleHash_RDR,
  uFloatHash_RDR, uIntHash_RDR, uWordHash_RDR :: RdrName
726 727 728 729 730 731 732 733 734 735 736 737 738

u1DataCon_RDR    = dataQual_RDR gHC_GENERICS (fsLit "U1")
par1DataCon_RDR  = dataQual_RDR gHC_GENERICS (fsLit "Par1")
rec1DataCon_RDR  = dataQual_RDR gHC_GENERICS (fsLit "Rec1")
k1DataCon_RDR    = dataQual_RDR gHC_GENERICS (fsLit "K1")
m1DataCon_RDR    = dataQual_RDR gHC_GENERICS (fsLit "M1")

l1DataCon_RDR     = dataQual_RDR gHC_GENERICS (fsLit "L1")
r1DataCon_RDR     = dataQual_RDR gHC_GENERICS (fsLit "R1")

prodDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit ":*:")
comp1DataCon_RDR  = dataQual_RDR gHC_GENERICS (fsLit "Comp1")

jpm@cs.ox.ac.uk's avatar
jpm@cs.ox.ac.uk committed
739 740 741 742 743
unPar1_RDR  = varQual_RDR gHC_GENERICS (fsLit "unPar1")
unRec1_RDR  = varQual_RDR gHC_GENERICS (fsLit "unRec1")
unK1_RDR    = varQual_RDR gHC_GENERICS (fsLit "unK1")
unComp1_RDR = varQual_RDR gHC_GENERICS (fsLit "unComp1")

744
from_RDR  = varQual_RDR gHC_GENERICS (fsLit "from")
745
from1_RDR = varQual_RDR gHC_GENERICS (fsLit "from1")
746
to_RDR    = varQual_RDR gHC_GENERICS (fsLit "to")
747 748 749 750
to1_RDR   = varQual_RDR gHC_GENERICS (fsLit "to1")

datatypeName_RDR  = varQual_RDR gHC_GENERICS (fsLit "datatypeName")
moduleName_RDR    = varQual_RDR gHC_GENERICS (fsLit "moduleName")
751
packageName_RDR   = varQual_RDR gHC_GENERICS (fsLit "packageName")
752
isNewtypeName_RDR = varQual_RDR gHC_GENERICS (fsLit "isNewtype")
753 754 755 756 757 758 759 760 761 762 763
selName_RDR       = varQual_RDR gHC_GENERICS (fsLit "selName")
conName_RDR       = varQual_RDR gHC_GENERICS (fsLit "conName")
conFixity_RDR     = varQual_RDR gHC_GENERICS (fsLit "conFixity")
conIsRecord_RDR   = varQual_RDR gHC_GENERICS (fsLit "conIsRecord")

prefixDataCon_RDR     = dataQual_RDR gHC_GENERICS (fsLit "Prefix")
infixDataCon_RDR      = dataQual_RDR gHC_GENERICS (fsLit "Infix")
leftAssocDataCon_RDR  = dataQual_RDR gHC_GENERICS (fsLit "LeftAssociative")
rightAssocDataCon_RDR = dataQual_RDR gHC_GENERICS (fsLit "RightAssociative")
notAssocDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit "NotAssociative")

764 765 766 767 768 769 770 771 772 773 774 775 776
uAddrDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit "UAddr")
uCharDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit "UChar")
uDoubleDataCon_RDR = dataQual_RDR gHC_GENERICS (fsLit "UDouble")
uFloatDataCon_RDR  = dataQual_RDR gHC_GENERICS (fsLit "UFloat")
uIntDataCon_RDR    = dataQual_RDR gHC_GENERICS (fsLit "UInt")
uWordDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit "UWord")

uAddrHash_RDR   = varQual_RDR gHC_GENERICS (fsLit "uAddr#")
uCharHash_RDR   = varQual_RDR gHC_GENERICS (fsLit "uChar#")
uDoubleHash_RDR = varQual_RDR gHC_GENERICS (fsLit "uDouble#")
uFloatHash_RDR  = varQual_RDR gHC_GENERICS (fsLit "uFloat#")
uIntHash_RDR    = varQual_RDR gHC_GENERICS (fsLit "uInt#")
uWordHash_RDR   = varQual_RDR gHC_GENERICS (fsLit "uWord#")
777

778 779
fmap_RDR, pure_RDR, ap_RDR, foldable_foldr_RDR, foldMap_RDR,
    traverse_RDR, mempty_RDR, mappend_RDR :: RdrName
780
fmap_RDR                = varQual_RDR gHC_BASE (fsLit "fmap")
781 782
pure_RDR                = nameRdrName pureAName
ap_RDR                  = nameRdrName apAName
783
foldable_foldr_RDR      = varQual_RDR dATA_FOLDABLE       (fsLit "foldr")
784
foldMap_RDR             = varQual_RDR dATA_FOLDABLE       (fsLit "foldMap")
785
traverse_RDR            = varQual_RDR dATA_TRAVERSABLE    (fsLit "traverse")
786 787
mempty_RDR              = varQual_RDR gHC_BASE            (fsLit "mempty")
mappend_RDR             = varQual_RDR gHC_BASE            (fsLit "mappend")
788

789 790 791
eqTyCon_RDR :: RdrName
eqTyCon_RDR = tcQual_RDR dATA_TYPE_EQUALITY (fsLit "~")

792
----------------------
Ian Lynagh's avatar
Ian Lynagh committed
793 794
varQual_RDR, tcQual_RDR, clsQual_RDR, dataQual_RDR
    :: Module -> FastString -> RdrName
795 796 797 798
varQual_RDR  mod str = mkOrig mod (mkOccNameFS varName str)
tcQual_RDR   mod str = mkOrig mod (mkOccNameFS tcName str)
clsQual_RDR  mod str = mkOrig mod (mkOccNameFS clsName str)
dataQual_RDR mod str = mkOrig mod (mkOccNameFS dataName str)
799

Austin Seipp's avatar
Austin Seipp committed
800 801 802
{-
************************************************************************
*                                                                      *
803
\subsection{Known-key names}
Austin Seipp's avatar
Austin Seipp committed
804 805
*                                                                      *
************************************************************************
806

807
Many of these Names are not really "built in", but some parts of the
808 809
compiler (notably the deriving mechanism) need to mention their names,
and it's convenient to write them all down in one place.