2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
7 #include "HsVersions.h"
11 pRELUDE, pRELUDE_BUILTIN, pRELUDE_CORE, pRELUDE_RATIO,
12 pRELUDE_LIST, pRELUDE_TEXT,
13 pRELUDE_PRIMIO, pRELUDE_IO, pRELUDE_PS,
14 gLASGOW_ST, gLASGOW_MISC,
16 -- finite maps for built-in things (for the renamer and typechecker):
17 builtinNameInfo, BuiltinNames(..),
18 BuiltinKeys(..), BuiltinIdInfos(..),
20 -- *odd* values that need to be reached out and grabbed:
26 nON_EXHAUSTIVE_GUARDS_ERROR_ID,
29 unpackCStringId, unpackCString2Id,
30 unpackCStringAppendId, unpackCStringFoldrId,
31 integerZeroId, integerPlusOneId,
32 integerPlusTwoId, integerMinusOneId,
34 -----------------------------------------------------
35 -- the rest of the export list is organised by *type*
36 -----------------------------------------------------
39 boolTyCon, boolTy, falseDataCon, trueDataCon,
41 -- types: Char#, Char, String (= [Char])
42 charPrimTy, charTy, stringTy,
43 charPrimTyCon, charTyCon, charDataCon,
45 -- type: Ordering (used in deriving)
46 orderingTy, ltDataCon, eqDataCon, gtDataCon,
48 -- types: Double#, Double
49 doublePrimTy, doubleTy,
50 doublePrimTyCon, doubleTyCon, doubleDataCon,
52 -- types: Float#, Float
54 floatPrimTyCon, floatTyCon, floatDataCon,
56 -- types: Glasgow *primitive* arrays, sequencing and I/O
57 mkPrimIoTy, -- to typecheck "mainPrimIO" & for _ccall_s
58 realWorldStatePrimTy, realWorldStateTy{-boxed-},
59 realWorldTy, realWorldTyCon, realWorldPrimId,
60 statePrimTyCon, stateDataCon, getStatePairingConInfo,
64 -- types: Void# (only used within the compiler)
65 voidPrimTy, voidPrimId,
67 -- types: Addr#, Int#, Word#, Int
68 intPrimTy, intTy, intPrimTyCon, intTyCon, intDataCon,
69 wordPrimTyCon, wordPrimTy, wordTy, wordTyCon, wordDataCon,
70 addrPrimTyCon, addrPrimTy, addrTy, addrTyCon, addrDataCon,
72 -- types: Integer, Rational (= Ratio Integer)
73 integerTy, rationalTy,
74 integerTyCon, integerDataCon,
75 rationalTyCon, ratioDataCon,
78 liftTyCon, liftDataCon, mkLiftTy,
81 listTyCon, mkListTy, nilDataCon, consDataCon,
86 -- for compilation of List Comprehensions and foldr
88 mkBuild, buildId, augmentId, appendId
90 -- and, finally, we must put in some (abstract) data types,
91 -- to make the interface self-sufficient
95 import PrelLoop ( primOpNameInfo )
98 import PrelMods -- Prelude module names
99 import PrelVals -- VALUES
100 import PrimOp ( PrimOp(..), allThePrimOps )
101 import PrimRep ( PrimRep(..) )
102 import TysPrim -- TYPES
106 import CmdLineOpts ( opt_HideBuiltinNames,
107 opt_HideMostBuiltinNames,
110 import FiniteMap ( FiniteMap, emptyFM, listToFM )
111 import Id ( mkTupleCon, GenId, Id(..) )
112 import Maybes ( catMaybes )
113 import Name ( getOrigName )
114 import RnHsSyn ( RnName(..) )
115 import TyCon ( tyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon )
117 import UniqFM ( UniqFM, emptyUFM, listToUFM )
118 import Unique -- *Key stuff
119 import Util ( nOfThem, panic )
122 %************************************************************************
124 \subsection[builtinNameInfo]{Lookup built-in names}
126 %************************************************************************
128 We have two ``builtin name funs,'' one to look up @TyCons@ and
129 @Classes@, the other to look up values.
132 builtinNameInfo :: ( BuiltinNames, BuiltinKeys, BuiltinIdInfos )
134 type BuiltinNames = FiniteMap FAST_STRING RnName -- WiredIn Ids/TyCons
135 type BuiltinKeys = FiniteMap FAST_STRING Unique -- Names with known uniques
136 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
139 = if opt_HideBuiltinNames then
145 else if opt_HideMostBuiltinNames then
147 listToFM min_assoc_wired,
153 listToFM assoc_wired,
155 listToUFM assoc_id_infos
159 min_assoc_wired -- min needed when compiling bits of Prelude
163 map pcTyConWiredInInfo prim_tycons,
164 map pcTyConWiredInInfo g_tycons,
165 map pcTyConWiredInInfo min_nonprim_tycon_list,
168 concat (map pcDataConWiredInInfo g_con_tycons),
169 concat (map pcDataConWiredInInfo min_nonprim_tycon_list),
172 map pcIdWiredInInfo wired_in_ids,
180 map pcTyConWiredInInfo prim_tycons,
181 map pcTyConWiredInInfo g_tycons,
182 map pcTyConWiredInInfo data_tycons,
183 map pcTyConWiredInInfo synonym_tycons,
186 concat (map pcDataConWiredInInfo g_con_tycons),
187 concat (map pcDataConWiredInInfo data_tycons),
190 map pcIdWiredInInfo wired_in_ids,
191 map pcIdWiredInInfo parallel_ids,
204 id_keys = map id_key id_keys_infos
205 id_key (str, uniq, info) = (str, uniq)
207 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
208 assoc_info (str, uniq, Just info) = Just (uniq, info)
209 assoc_info (str, uniq, Nothing) = Nothing
213 We let a lot of "non-standard" values be visible, so that we can make
214 sense of them in interface pragmas. It's cool, though they all have
215 "non-standard" names, so they won't get past the parser in user code.
217 The WiredIn TyCons and DataCons ...
229 mutableArrayPrimTyCon,
230 mutableByteArrayPrimTyCon,
239 = mkFunTyCon : g_con_tycons
242 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..32] ]
244 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
254 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
273 returnIntAndGMPTyCon,
275 stateAndAddrPrimTyCon,
276 stateAndArrayPrimTyCon,
277 stateAndByteArrayPrimTyCon,
278 stateAndCharPrimTyCon,
279 stateAndDoublePrimTyCon,
280 stateAndFloatPrimTyCon,
281 stateAndIntPrimTyCon,
282 stateAndMallocPtrPrimTyCon,
283 stateAndMutableArrayPrimTyCon,
284 stateAndMutableByteArrayPrimTyCon,
285 stateAndSynchVarPrimTyCon,
286 stateAndPtrPrimTyCon,
287 stateAndStablePtrPrimTyCon,
288 stateAndWordPrimTyCon,
301 pcTyConWiredInInfo :: TyCon -> (FAST_STRING, RnName)
302 pcTyConWiredInInfo tc = (snd (getOrigName tc), WiredInTyCon tc)
304 pcDataConWiredInInfo :: TyCon -> [(FAST_STRING, RnName)]
305 pcDataConWiredInInfo tycon
306 = [ (snd (getOrigName con), WiredInId con) | con <- tyConDataCons tycon ]
310 ToDo: Some of these should be moved to id_keys_infos!
314 pAT_ERROR_ID, -- occurs in i/faces
315 pAR_ERROR_ID, -- ditto
322 -- foldr/build Ids have magic unfoldings
327 unpackCStringAppendId,
332 = if not opt_ForConcurrent then
348 pcIdWiredInInfo :: Id -> (FAST_STRING, RnName)
349 pcIdWiredInInfo id = (snd (getOrigName id), WiredInId id)
352 WiredIn primitive numeric operations ...
355 = map primOpNameInfo allThePrimOps ++ map fn funny_name_primops
357 fn (op,s) = case (primOpNameInfo op) of (_,n) -> (s,n)
361 (IntAddOp, SLIT("+#")),
362 (IntSubOp, SLIT("-#")),
363 (IntMulOp, SLIT("*#")),
364 (IntGtOp, SLIT(">#")),
365 (IntGeOp, SLIT(">=#")),
366 (IntEqOp, SLIT("==#")),
367 (IntNeOp, SLIT("/=#")),
368 (IntLtOp, SLIT("<#")),
369 (IntLeOp, SLIT("<=#")),
370 (DoubleAddOp, SLIT("+##")),
371 (DoubleSubOp, SLIT("-##")),
372 (DoubleMulOp, SLIT("*##")),
373 (DoubleDivOp, SLIT("/##")),
374 (DoublePowerOp, SLIT("**##")),
375 (DoubleGtOp, SLIT(">##")),
376 (DoubleGeOp, SLIT(">=##")),
377 (DoubleEqOp, SLIT("==##")),
378 (DoubleNeOp, SLIT("/=##")),
379 (DoubleLtOp, SLIT("<##")),
380 (DoubleLeOp, SLIT("<=##"))
385 Ids, Synonyms, Classes and ClassOps with builtin keys.
386 For the Ids we may also have some builtin IdInfo.
388 id_keys_infos :: [(FAST_STRING, Unique, Maybe IdInfo)]
395 (SLIT("IO"), iOTyConKey) -- SLIT("PreludeMonadicIO")
400 (SLIT("Eq"), eqClassKey),
401 (SLIT("Ord"), ordClassKey),
402 (SLIT("Num"), numClassKey),
403 (SLIT("Real"), realClassKey),
404 (SLIT("Integral"), integralClassKey),
405 (SLIT("Fractional"), fractionalClassKey),
406 (SLIT("Floating"), floatingClassKey),
407 (SLIT("RealFrac"), realFracClassKey),
408 (SLIT("RealFloat"), realFloatClassKey),
409 (SLIT("Ix"), ixClassKey),
410 (SLIT("Enum"), enumClassKey),
411 (SLIT("Show"), showClassKey),
412 (SLIT("Read"), readClassKey),
413 (SLIT("Monad"), monadClassKey),
414 (SLIT("MonadZero"), monadZeroClassKey),
415 (SLIT("Binary"), binaryClassKey),
416 (SLIT("_CCallable"), cCallableClassKey),
417 (SLIT("_CReturnable"), cReturnableClassKey)
422 (SLIT("fromInt"), fromIntClassOpKey),
423 (SLIT("fromInteger"), fromIntegerClassOpKey),
424 (SLIT("fromRational"), fromRationalClassOpKey),
425 (SLIT("enumFrom"), enumFromClassOpKey),
426 (SLIT("enumFromThen"), enumFromThenClassOpKey),
427 (SLIT("enumFromTo"), enumFromToClassOpKey),
428 (SLIT("enumFromThenTo"), enumFromThenToClassOpKey),
429 (SLIT("=="), eqClassOpKey),
430 (SLIT(">="), geClassOpKey)