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 -- finite maps for built-in things (for the renamer and typechecker):
12 builtinNameInfo, BuiltinNames(..),
13 BuiltinKeys(..), BuiltinIdInfos(..),
15 maybeCharLikeTyCon, maybeIntLikeTyCon
19 import PrelLoop ( primOpNameInfo )
22 import PrelMods -- Prelude module names
23 import PrelVals -- VALUES
24 import PrimOp ( PrimOp(..), allThePrimOps )
25 import PrimRep ( PrimRep(..) )
26 import TysPrim -- TYPES
30 import CmdLineOpts ( opt_HideBuiltinNames,
31 opt_HideMostBuiltinNames,
34 import FiniteMap ( FiniteMap, emptyFM, listToFM )
35 import Id ( mkTupleCon, GenId, Id(..) )
36 import Maybes ( catMaybes )
37 import Name ( origName, nameOf )
38 import RnHsSyn ( RnName(..) )
39 import TyCon ( tyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon )
41 import UniqFM ( UniqFM, emptyUFM, listToUFM )
42 import Unique -- *Key stuff
43 import Util ( nOfThem, panic )
46 %************************************************************************
48 \subsection[builtinNameInfo]{Lookup built-in names}
50 %************************************************************************
52 We have two ``builtin name funs,'' one to look up @TyCons@ and
53 @Classes@, the other to look up values.
56 builtinNameInfo :: ( BuiltinNames, BuiltinKeys, BuiltinIdInfos )
58 type BuiltinNames = (FiniteMap FAST_STRING RnName, -- WiredIn Ids
59 FiniteMap FAST_STRING RnName) -- WiredIn TyCons
60 -- Two maps because "[]" is in both...
61 type BuiltinKeys = FiniteMap FAST_STRING (Unique, Name -> RnName)
62 -- Names with known uniques
63 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
66 = if opt_HideBuiltinNames then
72 else if opt_HideMostBuiltinNames then
74 (listToFM min_assoc_val_wired, listToFM min_assoc_tc_wired),
80 (listToFM assoc_val_wired, listToFM assoc_tc_wired),
82 listToUFM assoc_id_infos
86 min_assoc_val_wired -- min needed when compiling bits of Prelude
89 concat (map pcDataConWiredInInfo g_con_tycons),
90 concat (map pcDataConWiredInInfo min_nonprim_tycon_list),
93 map pcIdWiredInInfo wired_in_ids,
99 map pcTyConWiredInInfo prim_tycons,
100 map pcTyConWiredInInfo g_tycons,
101 map pcTyConWiredInInfo min_nonprim_tycon_list
107 concat (map pcDataConWiredInInfo g_con_tycons),
108 concat (map pcDataConWiredInInfo data_tycons),
111 map pcIdWiredInInfo wired_in_ids,
112 map pcIdWiredInInfo parallel_ids,
118 map pcTyConWiredInInfo prim_tycons,
119 map pcTyConWiredInInfo g_tycons,
120 map pcTyConWiredInInfo data_tycons,
121 map pcTyConWiredInInfo synonym_tycons
133 id_keys = map id_key id_keys_infos
134 id_key (str, uniq, info) = (str, (uniq, RnImplicit))
136 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
137 assoc_info (str, uniq, Just info) = Just (uniq, info)
138 assoc_info (str, uniq, Nothing) = Nothing
142 We let a lot of "non-standard" values be visible, so that we can make
143 sense of them in interface pragmas. It's cool, though they all have
144 "non-standard" names, so they won't get past the parser in user code.
146 The WiredIn TyCons and DataCons ...
157 , foreignObjPrimTyCon
158 , mutableArrayPrimTyCon
159 , mutableByteArrayPrimTyCon
168 = mkFunTyCon : g_con_tycons
171 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..32] ]
173 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
183 , return2GMPsTyCon -- ADR asked for these last two (WDP 94/11)
184 , returnIntAndGMPTyCon
201 , returnIntAndGMPTyCon
203 , stateAndAddrPrimTyCon
204 , stateAndArrayPrimTyCon
205 , stateAndByteArrayPrimTyCon
206 , stateAndCharPrimTyCon
207 , stateAndDoublePrimTyCon
208 , stateAndFloatPrimTyCon
209 , stateAndIntPrimTyCon
210 , stateAndForeignObjPrimTyCon
211 , stateAndMutableArrayPrimTyCon
212 , stateAndMutableByteArrayPrimTyCon
213 , stateAndSynchVarPrimTyCon
214 , stateAndPtrPrimTyCon
215 , stateAndStablePtrPrimTyCon
216 , stateAndWordPrimTyCon
228 pcTyConWiredInInfo :: TyCon -> (FAST_STRING, RnName)
229 pcTyConWiredInInfo tc = (nameOf (origName tc), WiredInTyCon tc)
231 pcDataConWiredInInfo :: TyCon -> [(FAST_STRING, RnName)]
232 pcDataConWiredInInfo tycon
233 = [ (nameOf (origName con), WiredInId con) | con <- tyConDataCons tycon ]
237 ToDo: Some of these should be moved to id_keys_infos!
241 , pAT_ERROR_ID -- occurs in i/faces
242 , pAR_ERROR_ID -- ditto
249 -- foldr/build Ids have magic unfoldings
254 , unpackCStringAppendId
255 , unpackCStringFoldrId
259 = if not opt_ForConcurrent then
274 pcIdWiredInInfo :: Id -> (FAST_STRING, RnName)
275 pcIdWiredInInfo id = (nameOf (origName id), WiredInId id)
278 WiredIn primitive numeric operations ...
281 = map primOpNameInfo allThePrimOps ++ map fn funny_name_primops
283 fn (op,s) = case (primOpNameInfo op) of (_,n) -> (s,n)
286 = [ (IntAddOp, SLIT("+#"))
287 , (IntSubOp, SLIT("-#"))
288 , (IntMulOp, SLIT("*#"))
289 , (IntGtOp, SLIT(">#"))
290 , (IntGeOp, SLIT(">=#"))
291 , (IntEqOp, SLIT("==#"))
292 , (IntNeOp, SLIT("/=#"))
293 , (IntLtOp, SLIT("<#"))
294 , (IntLeOp, SLIT("<=#"))
295 , (DoubleAddOp, SLIT("+##"))
296 , (DoubleSubOp, SLIT("-##"))
297 , (DoubleMulOp, SLIT("*##"))
298 , (DoubleDivOp, SLIT("/##"))
299 , (DoublePowerOp, SLIT("**##"))
300 , (DoubleGtOp, SLIT(">##"))
301 , (DoubleGeOp, SLIT(">=##"))
302 , (DoubleEqOp, SLIT("==##"))
303 , (DoubleNeOp, SLIT("/=##"))
304 , (DoubleLtOp, SLIT("<##"))
305 , (DoubleLeOp, SLIT("<=##"))
310 Ids, Synonyms, Classes and ClassOps with builtin keys.
311 For the Ids we may also have some builtin IdInfo.
313 id_keys_infos :: [(FAST_STRING, Unique, Maybe IdInfo)]
315 = [ (SLIT("main"), mainIdKey, Nothing)
316 , (SLIT("mainPrimIO"), mainPrimIOIdKey, Nothing)
320 = [ (SLIT("IO"), (iOTyConKey, RnImplicitTyCon))
323 -- this "class_keys" list *must* include:
324 -- classes that are grabbed by key (e.g., eqClassKey)
325 -- classes in "Class.standardClassKeys" (quite a few)
328 = [ (s, (k, RnImplicitClass)) | (s,k) <-
329 [ (SLIT("Eq"), eqClassKey) -- mentioned, derivable
330 , (SLIT("Eval"), evalClassKey) -- mentioned
331 , (SLIT("Ord"), ordClassKey) -- derivable
332 , (SLIT("Num"), numClassKey) -- mentioned, numeric
333 , (SLIT("Real"), realClassKey) -- numeric
334 , (SLIT("Integral"), integralClassKey) -- numeric
335 , (SLIT("Fractional"), fractionalClassKey) -- numeric
336 , (SLIT("Floating"), floatingClassKey) -- numeric
337 , (SLIT("RealFrac"), realFracClassKey) -- numeric
338 , (SLIT("RealFloat"), realFloatClassKey) -- numeric
339 -- , (SLIT("Ix"), ixClassKey) -- derivable (but it isn't Prelude.Ix; hmmm)
340 -- see *hack* in Rename
341 , (SLIT("Bounded"), boundedClassKey) -- derivable
342 , (SLIT("Enum"), enumClassKey) -- derivable
343 , (SLIT("Show"), showClassKey) -- derivable
344 , (SLIT("Read"), readClassKey) -- derivable
345 , (SLIT("Monad"), monadClassKey)
346 , (SLIT("MonadZero"), monadZeroClassKey)
347 , (SLIT("MonadPlus"), monadPlusClassKey)
348 , (SLIT("Functor"), functorClassKey)
349 , (SLIT("CCallable"), cCallableClassKey) -- mentioned, ccallish
350 , (SLIT("CReturnable"), cReturnableClassKey) -- mentioned, ccallish
354 = [ (s, (k, RnImplicit)) | (s,k) <-
355 [ (SLIT("fromInt"), fromIntClassOpKey)
356 , (SLIT("fromInteger"), fromIntegerClassOpKey)
357 , (SLIT("fromRational"), fromRationalClassOpKey)
358 , (SLIT("enumFrom"), enumFromClassOpKey)
359 , (SLIT("enumFromThen"), enumFromThenClassOpKey)
360 , (SLIT("enumFromTo"), enumFromToClassOpKey)
361 , (SLIT("enumFromThenTo"), enumFromThenToClassOpKey)
362 , (SLIT("=="), eqClassOpKey)
366 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
368 maybeCharLikeTyCon tc = if (uniqueOf tc == charDataConKey) then Just charDataCon else Nothing
369 maybeIntLikeTyCon tc = if (uniqueOf tc == intDataConKey) then Just intDataCon else Nothing