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 ( origName, nameOf )
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
135 FiniteMap FAST_STRING RnName) -- WiredIn TyCons
136 -- Two maps because "[]" is in both...
137 type BuiltinKeys = FiniteMap FAST_STRING (Unique, Name -> RnName)
138 -- Names with known uniques
139 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
142 = if opt_HideBuiltinNames then
148 else if opt_HideMostBuiltinNames then
150 (listToFM min_assoc_val_wired, listToFM min_assoc_tc_wired),
156 (listToFM assoc_val_wired, listToFM assoc_tc_wired),
158 listToUFM assoc_id_infos
162 min_assoc_val_wired -- min needed when compiling bits of Prelude
165 concat (map pcDataConWiredInInfo g_con_tycons),
166 concat (map pcDataConWiredInInfo min_nonprim_tycon_list),
169 map pcIdWiredInInfo wired_in_ids,
175 map pcTyConWiredInInfo prim_tycons,
176 map pcTyConWiredInInfo g_tycons,
177 map pcTyConWiredInInfo min_nonprim_tycon_list
183 concat (map pcDataConWiredInInfo g_con_tycons),
184 concat (map pcDataConWiredInInfo data_tycons),
187 map pcIdWiredInInfo wired_in_ids,
188 map pcIdWiredInInfo parallel_ids,
194 map pcTyConWiredInInfo prim_tycons,
195 map pcTyConWiredInInfo g_tycons,
196 map pcTyConWiredInInfo data_tycons,
197 map pcTyConWiredInInfo synonym_tycons
209 id_keys = map id_key id_keys_infos
210 id_key (str, uniq, info) = (str, (uniq, RnImplicit))
212 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
213 assoc_info (str, uniq, Just info) = Just (uniq, info)
214 assoc_info (str, uniq, Nothing) = Nothing
218 We let a lot of "non-standard" values be visible, so that we can make
219 sense of them in interface pragmas. It's cool, though they all have
220 "non-standard" names, so they won't get past the parser in user code.
222 The WiredIn TyCons and DataCons ...
234 , mutableArrayPrimTyCon
235 , mutableByteArrayPrimTyCon
244 = mkFunTyCon : g_con_tycons
247 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..32] ]
249 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
259 , return2GMPsTyCon -- ADR asked for these last two (WDP 94/11)
260 , returnIntAndGMPTyCon
277 , returnIntAndGMPTyCon
279 , stateAndAddrPrimTyCon
280 , stateAndArrayPrimTyCon
281 , stateAndByteArrayPrimTyCon
282 , stateAndCharPrimTyCon
283 , stateAndDoublePrimTyCon
284 , stateAndFloatPrimTyCon
285 , stateAndIntPrimTyCon
286 , stateAndMallocPtrPrimTyCon
287 , stateAndMutableArrayPrimTyCon
288 , stateAndMutableByteArrayPrimTyCon
289 , stateAndSynchVarPrimTyCon
290 , stateAndPtrPrimTyCon
291 , stateAndStablePtrPrimTyCon
292 , stateAndWordPrimTyCon
304 pcTyConWiredInInfo :: TyCon -> (FAST_STRING, RnName)
305 pcTyConWiredInInfo tc = (nameOf (origName tc), WiredInTyCon tc)
307 pcDataConWiredInInfo :: TyCon -> [(FAST_STRING, RnName)]
308 pcDataConWiredInInfo tycon
309 = [ (nameOf (origName con), WiredInId con) | con <- tyConDataCons tycon ]
313 ToDo: Some of these should be moved to id_keys_infos!
317 , pAT_ERROR_ID -- occurs in i/faces
318 , pAR_ERROR_ID -- ditto
325 -- foldr/build Ids have magic unfoldings
330 , unpackCStringAppendId
331 , unpackCStringFoldrId
335 = if not opt_ForConcurrent then
351 pcIdWiredInInfo :: Id -> (FAST_STRING, RnName)
352 pcIdWiredInInfo id = (nameOf (origName id), WiredInId id)
355 WiredIn primitive numeric operations ...
358 = map primOpNameInfo allThePrimOps ++ map fn funny_name_primops
360 fn (op,s) = case (primOpNameInfo op) of (_,n) -> (s,n)
363 = [ (IntAddOp, SLIT("+#"))
364 , (IntSubOp, SLIT("-#"))
365 , (IntMulOp, SLIT("*#"))
366 , (IntGtOp, SLIT(">#"))
367 , (IntGeOp, SLIT(">=#"))
368 , (IntEqOp, SLIT("==#"))
369 , (IntNeOp, SLIT("/=#"))
370 , (IntLtOp, SLIT("<#"))
371 , (IntLeOp, SLIT("<=#"))
372 , (DoubleAddOp, SLIT("+##"))
373 , (DoubleSubOp, SLIT("-##"))
374 , (DoubleMulOp, SLIT("*##"))
375 , (DoubleDivOp, SLIT("/##"))
376 , (DoublePowerOp, SLIT("**##"))
377 , (DoubleGtOp, SLIT(">##"))
378 , (DoubleGeOp, SLIT(">=##"))
379 , (DoubleEqOp, SLIT("==##"))
380 , (DoubleNeOp, SLIT("/=##"))
381 , (DoubleLtOp, SLIT("<##"))
382 , (DoubleLeOp, SLIT("<=##"))
387 Ids, Synonyms, Classes and ClassOps with builtin keys.
388 For the Ids we may also have some builtin IdInfo.
390 id_keys_infos :: [(FAST_STRING, Unique, Maybe IdInfo)]
392 = [ (SLIT("main"), mainIdKey, Nothing)
393 , (SLIT("mainPrimIO"), mainPrimIOIdKey, Nothing)
397 = [ (SLIT("IO"), (iOTyConKey, RnImplicitTyCon))
400 -- this "class_keys" list *must* include:
401 -- classes that are grabbed by key (e.g., eqClassKey)
402 -- classes in "Class.standardClassKeys" (quite a few)
405 = [ (s, (k, RnImplicitClass)) | (s,k) <-
406 [ (SLIT("Eq"), eqClassKey) -- mentioned, derivable
407 , (SLIT("Ord"), ordClassKey) -- derivable
408 , (SLIT("Num"), numClassKey) -- mentioned, numeric
409 , (SLIT("Real"), realClassKey) -- numeric
410 , (SLIT("Integral"), integralClassKey) -- numeric
411 , (SLIT("Fractional"), fractionalClassKey) -- numeric
412 , (SLIT("Floating"), floatingClassKey) -- numeric
413 , (SLIT("RealFrac"), realFracClassKey) -- numeric
414 , (SLIT("RealFloat"), realFloatClassKey) -- numeric
415 -- , (SLIT("Ix"), ixClassKey)
416 , (SLIT("Bounded"), boundedClassKey) -- derivable
417 , (SLIT("Enum"), enumClassKey) -- derivable
418 , (SLIT("Show"), showClassKey) -- derivable
419 , (SLIT("Read"), readClassKey) -- derivable
420 , (SLIT("Monad"), monadClassKey)
421 , (SLIT("MonadZero"), monadZeroClassKey)
422 , (SLIT("CCallable"), cCallableClassKey) -- mentioned, ccallish
423 , (SLIT("CReturnable"), cReturnableClassKey) -- mentioned, ccallish
427 = [ (s, (k, RnImplicit)) | (s,k) <-
428 [ (SLIT("fromInt"), fromIntClassOpKey)
429 , (SLIT("fromInteger"), fromIntegerClassOpKey)
430 , (SLIT("fromRational"), fromRationalClassOpKey)
431 , (SLIT("enumFrom"), enumFromClassOpKey)
432 , (SLIT("enumFromThen"), enumFromThenClassOpKey)
433 , (SLIT("enumFromTo"), enumFromToClassOpKey)
434 , (SLIT("enumFromThenTo"), enumFromThenToClassOpKey)
435 , (SLIT("=="), eqClassOpKey)