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"
10 -- finite maps for built-in things (for the renamer and typechecker):
11 builtinNames, builtinKeys, derivingOccurrences,
14 maybeCharLikeTyCon, maybeIntLikeTyCon,
16 eq_RDR, ne_RDR, le_RDR, lt_RDR, ge_RDR, gt_RDR, max_RDR, min_RDR, compare_RDR,
17 minBound_RDR, maxBound_RDR, enumFrom_RDR, enumFromTo_RDR, enumFromThen_RDR,
18 enumFromThenTo_RDR, fromEnum_RDR,
19 range_RDR, index_RDR, inRange_RDR, readsPrec_RDR, readList_RDR,
20 showsPrec_RDR, showList_RDR, plus_RDR, times_RDR, ltTag_RDR, eqTag_RDR, gtTag_RDR,
21 eqH_Char_RDR, ltH_Char_RDR, eqH_Word_RDR, ltH_Word_RDR, eqH_Addr_RDR, ltH_Addr_RDR,
22 eqH_Float_RDR, ltH_Float_RDR, eqH_Double_RDR, ltH_Double_RDR, eqH_Int_RDR, ltH_Int_RDR,
23 geH_RDR, leH_RDR, minusH_RDR, false_RDR, true_RDR, and_RDR, not_RDR, append_RDR,
24 map_RDR, compose_RDR, mkInt_RDR, error_RDR, showString_RDR, showParen_RDR, readParen_RDR,
25 lex_RDR, showSpace_RDR, showList___RDR, readList___RDR, negate_RDR,
27 numClass_RDR, fractionalClass_RDR, eqClass_RDR, ccallableClass_RDR, creturnableClass_RDR,
28 monadZeroClass_RDR, enumClass_RDR, evalClass_RDR, ordClass_RDR,
30 needsDataDeclCtxtClassKeys, cCallishClassKeys, isNoDictClass,
31 isNumericClass, isStandardClass, isCcallishClass
35 IMPORT_DELOOPER(PrelLoop) ( primOpName )
36 -- IMPORT_DELOOPER(IdLoop) ( SpecEnv )
39 import PrelMods -- Prelude module names
40 import PrelVals -- VALUES
41 import PrimOp ( PrimOp(..), allThePrimOps )
42 import PrimRep ( PrimRep(..) )
43 import TysPrim -- TYPES
47 import SpecEnv ( SpecEnv )
48 import RdrHsSyn ( RdrName(..), varQual, tcQual, qual )
49 import Id ( GenId, SYN_IE(Id) )
50 import Name ( Name, OccName(..), DefnInfo(..), Provenance(..),
51 getName, mkGlobalName, modAndOcc )
52 import Class ( Class(..), GenClass, classKey )
53 import TyCon ( tyConDataCons, mkFunTyCon, TyCon )
56 import Unique -- *Key stuff
57 import UniqFM ( UniqFM, listToUFM )
61 %************************************************************************
63 \subsection[builtinNameInfo]{Lookup built-in names}
65 %************************************************************************
67 We have two ``builtin name funs,'' one to look up @TyCons@ and
68 @Classes@, the other to look up values.
71 type BuiltinNames = Bag Name
73 builtinNames :: BuiltinNames
76 unionManyBags (map getTyConNames wired_in_tycons) `unionBags`
79 listToBag (map getName wired_in_ids) `unionBags`
82 listToBag (map (getName.primOpName) allThePrimOps) `unionBags`
84 -- Other names with magic keys
90 getTyConNames :: TyCon -> Bag Name
92 = getName tycon `consBag` listToBag (map getName (tyConDataCons tycon))
93 -- Synonyms return empty list of constructors
97 We let a lot of "non-standard" values be visible, so that we can make
98 sense of them in interface pragmas. It's cool, though they all have
99 "non-standard" names, so they won't get past the parser in user code.
101 %************************************************************************
103 \subsection{Wired in TyCons}
105 %************************************************************************
109 wired_in_tycons = [mkFunTyCon] ++
122 , foreignObjPrimTyCon
123 , mutableArrayPrimTyCon
124 , mutableByteArrayPrimTyCon
132 tuple_tycons = unitTyCon : [tupleTyCon i | i <- [2..37] ]
148 , returnIntAndGMPTyCon
151 , stateAndAddrPrimTyCon
152 , stateAndArrayPrimTyCon
153 , stateAndByteArrayPrimTyCon
154 , stateAndCharPrimTyCon
155 , stateAndDoublePrimTyCon
156 , stateAndFloatPrimTyCon
157 , stateAndForeignObjPrimTyCon
158 , stateAndIntPrimTyCon
159 , stateAndMutableArrayPrimTyCon
160 , stateAndMutableByteArrayPrimTyCon
161 , stateAndPtrPrimTyCon
162 , stateAndStablePtrPrimTyCon
163 , stateAndSynchVarPrimTyCon
164 , stateAndWordPrimTyCon
170 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
178 , return2GMPsTyCon -- ADR asked for these last two (WDP 94/11)
179 , returnIntAndGMPTyCon
183 %************************************************************************
185 \subsection{Wired in Ids}
187 %************************************************************************
190 ToDo: Some of these should be moved to id_keys_infos!
200 , iRREFUT_PAT_ERROR_ID
205 , nON_EXHAUSTIVE_GUARDS_ERROR_ID
206 , nO_DEFAULT_METHOD_ERROR_ID
207 , nO_EXPLICIT_METHOD_ERROR_ID
217 , unpackCStringAppendId
218 , unpackCStringFoldrId
237 %************************************************************************
239 \subsection{Built-in keys}
241 %************************************************************************
243 Ids, Synonyms, Classes and ClassOps with builtin keys.
246 getKeyOrig :: (Module, OccName, Unique) -> Name
247 getKeyOrig (mod, occ, uniq) = mkGlobalName uniq mod occ VanillaDefn Implicit
249 builtinKeys :: [Name]
253 -- Type constructors (synonyms especially)
254 (iO_BASE, TCOcc SLIT("IO"), iOTyConKey)
255 , (pREL_BASE, TCOcc SLIT("Ordering"), orderingTyConKey)
256 , (pREL_NUM, TCOcc SLIT("Rational"), rationalTyConKey)
257 , (pREL_NUM, TCOcc SLIT("Ratio"), ratioTyConKey)
260 -- Classes. *Must* include:
261 -- classes that are grabbed by key (e.g., eqClassKey)
262 -- classes in "Class.standardClassKeys" (quite a few)
263 , (pREL_BASE, TCOcc SLIT("Eq"), eqClassKey) -- mentioned, derivable
264 , (pREL_BASE, TCOcc SLIT("Eval"), evalClassKey) -- mentioned
265 , (pREL_BASE, TCOcc SLIT("Ord"), ordClassKey) -- derivable
266 , (pREL_BASE, TCOcc SLIT("Bounded"), boundedClassKey) -- derivable
267 , (pREL_BASE, TCOcc SLIT("Num"), numClassKey) -- mentioned, numeric
268 , (pREL_BASE, TCOcc SLIT("Enum"), enumClassKey) -- derivable
269 , (pREL_BASE, TCOcc SLIT("Monad"), monadClassKey)
270 , (pREL_BASE, TCOcc SLIT("MonadZero"), monadZeroClassKey)
271 , (pREL_BASE, TCOcc SLIT("MonadPlus"), monadPlusClassKey)
272 , (pREL_BASE, TCOcc SLIT("Functor"), functorClassKey)
273 , (pREL_BASE, TCOcc SLIT("Show"), showClassKey) -- derivable
274 , (pREL_NUM, TCOcc SLIT("Real"), realClassKey) -- numeric
275 , (pREL_NUM, TCOcc SLIT("Integral"), integralClassKey) -- numeric
276 , (pREL_NUM, TCOcc SLIT("Fractional"), fractionalClassKey) -- numeric
277 , (pREL_NUM, TCOcc SLIT("Floating"), floatingClassKey) -- numeric
278 , (pREL_NUM, TCOcc SLIT("RealFrac"), realFracClassKey) -- numeric
279 , (pREL_NUM, TCOcc SLIT("RealFloat"), realFloatClassKey) -- numeric
280 , (pREL_READ, TCOcc SLIT("Read"), readClassKey) -- derivable
281 , (iX, TCOcc SLIT("Ix"), ixClassKey) -- derivable (but it isn't Prelude.Ix; hmmm)
282 , (fOREIGN, TCOcc SLIT("CCallable"), cCallableClassKey) -- mentioned, ccallish
283 , (fOREIGN, TCOcc SLIT("CReturnable"), cReturnableClassKey) -- mentioned, ccallish
287 , (pREL_BASE, VarOcc SLIT("fromInt"), fromIntClassOpKey)
288 , (pREL_BASE, VarOcc SLIT("fromInteger"), fromIntegerClassOpKey)
289 , (pREL_BASE, VarOcc SLIT("enumFrom"), enumFromClassOpKey)
290 , (pREL_BASE, VarOcc SLIT("enumFromThen"), enumFromThenClassOpKey)
291 , (pREL_BASE, VarOcc SLIT("enumFromTo"), enumFromToClassOpKey)
292 , (pREL_BASE, VarOcc SLIT("enumFromThenTo"), enumFromThenToClassOpKey)
293 , (pREL_BASE, VarOcc SLIT("fromEnum"), fromEnumClassOpKey)
294 , (pREL_BASE, VarOcc SLIT("=="), eqClassOpKey)
295 , (pREL_BASE, VarOcc SLIT(">>="), thenMClassOpKey)
296 , (pREL_BASE, VarOcc SLIT("zero"), zeroClassOpKey)
297 , (pREL_NUM, VarOcc SLIT("fromRational"), fromRationalClassOpKey)
301 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
304 maybeCharLikeTyCon tc = if (uniqueOf tc == charDataConKey) then Just charDataCon else Nothing
305 maybeIntLikeTyCon tc = if (uniqueOf tc == intDataConKey) then Just intDataCon else Nothing
308 %************************************************************************
310 \subsection{Commonly-used RdrNames}
312 %************************************************************************
314 These RdrNames are not really "built in", but some parts of the compiler
315 (notably the deriving mechanism) need to mention their names, and it's convenient
316 to write them all down in one place.
319 prelude_primop op = qual (modAndOcc (primOpName op))
321 eqClass_RDR = tcQual (pREL_BASE, SLIT("Eq"))
322 ordClass_RDR = tcQual (pREL_BASE, SLIT("Ord"))
323 evalClass_RDR = tcQual (pREL_BASE, SLIT("Eval"))
324 monadZeroClass_RDR = tcQual (pREL_BASE, SLIT("MonadZero"))
325 enumClass_RDR = tcQual (pREL_BASE, SLIT("Enum"))
326 numClass_RDR = tcQual (pREL_BASE, SLIT("Num"))
327 fractionalClass_RDR = tcQual (pREL_NUM, SLIT("Fractional"))
328 ccallableClass_RDR = tcQual (fOREIGN, SLIT("CCallable"))
329 creturnableClass_RDR = tcQual (fOREIGN, SLIT("CReturnable"))
331 negate_RDR = varQual (pREL_BASE, SLIT("negate"))
332 eq_RDR = varQual (pREL_BASE, SLIT("=="))
333 ne_RDR = varQual (pREL_BASE, SLIT("/="))
334 le_RDR = varQual (pREL_BASE, SLIT("<="))
335 lt_RDR = varQual (pREL_BASE, SLIT("<"))
336 ge_RDR = varQual (pREL_BASE, SLIT(">="))
337 gt_RDR = varQual (pREL_BASE, SLIT(">"))
338 ltTag_RDR = varQual (pREL_BASE, SLIT("LT"))
339 eqTag_RDR = varQual (pREL_BASE, SLIT("EQ"))
340 gtTag_RDR = varQual (pREL_BASE, SLIT("GT"))
341 max_RDR = varQual (pREL_BASE, SLIT("max"))
342 min_RDR = varQual (pREL_BASE, SLIT("min"))
343 compare_RDR = varQual (pREL_BASE, SLIT("compare"))
344 minBound_RDR = varQual (pREL_BASE, SLIT("minBound"))
345 maxBound_RDR = varQual (pREL_BASE, SLIT("maxBound"))
346 false_RDR = varQual (pREL_BASE, SLIT("False"))
347 true_RDR = varQual (pREL_BASE, SLIT("True"))
348 and_RDR = varQual (pREL_BASE, SLIT("&&"))
349 not_RDR = varQual (pREL_BASE, SLIT("not"))
350 compose_RDR = varQual (pREL_BASE, SLIT("."))
351 append_RDR = varQual (pREL_BASE, SLIT("++"))
352 map_RDR = varQual (pREL_BASE, SLIT("map"))
354 showList___RDR = varQual (pREL_BASE, SLIT("showList__"))
355 showsPrec_RDR = varQual (pREL_BASE, SLIT("showsPrec"))
356 showList_RDR = varQual (pREL_BASE, SLIT("showList"))
357 showSpace_RDR = varQual (pREL_BASE, SLIT("showSpace"))
358 showString_RDR = varQual (pREL_BASE, SLIT("showString"))
359 showParen_RDR = varQual (pREL_BASE, SLIT("showParen"))
361 range_RDR = varQual (iX, SLIT("range"))
362 index_RDR = varQual (iX, SLIT("index"))
363 inRange_RDR = varQual (iX, SLIT("inRange"))
365 readsPrec_RDR = varQual (pREL_READ, SLIT("readsPrec"))
366 readList_RDR = varQual (pREL_READ, SLIT("readList"))
367 readParen_RDR = varQual (pREL_READ, SLIT("readParen"))
368 lex_RDR = varQual (pREL_READ, SLIT("lex"))
369 readList___RDR = varQual (pREL_READ, SLIT("readList__"))
371 fromEnum_RDR = varQual (pREL_BASE, SLIT("fromEnum"))
372 enumFrom_RDR = varQual (pREL_BASE, SLIT("enumFrom"))
373 enumFromTo_RDR = varQual (pREL_BASE, SLIT("enumFromTo"))
374 enumFromThen_RDR = varQual (pREL_BASE, SLIT("enumFromThen"))
375 enumFromThenTo_RDR = varQual (pREL_BASE, SLIT("enumFromThenTo"))
376 plus_RDR = varQual (pREL_BASE, SLIT("+"))
377 times_RDR = varQual (pREL_BASE, SLIT("*"))
378 mkInt_RDR = varQual (pREL_BASE, SLIT("I#"))
380 error_RDR = varQual (iO_BASE, SLIT("error"))
382 eqH_Char_RDR = prelude_primop CharEqOp
383 ltH_Char_RDR = prelude_primop CharLtOp
384 eqH_Word_RDR = prelude_primop WordEqOp
385 ltH_Word_RDR = prelude_primop WordLtOp
386 eqH_Addr_RDR = prelude_primop AddrEqOp
387 ltH_Addr_RDR = prelude_primop AddrLtOp
388 eqH_Float_RDR = prelude_primop FloatEqOp
389 ltH_Float_RDR = prelude_primop FloatLtOp
390 eqH_Double_RDR = prelude_primop DoubleEqOp
391 ltH_Double_RDR = prelude_primop DoubleLtOp
392 eqH_Int_RDR = prelude_primop IntEqOp
393 ltH_Int_RDR = prelude_primop IntLtOp
394 geH_RDR = prelude_primop IntGeOp
395 leH_RDR = prelude_primop IntLeOp
396 minusH_RDR = prelude_primop IntSubOp
398 intType_RDR = qual (modAndOcc intTyCon)
401 %************************************************************************
403 \subsection[Class-std-groups]{Standard groups of Prelude classes}
405 %************************************************************************
407 @derivableClassKeys@ is also used in checking \tr{deriving} constructs
410 @derivingOccurrences@ maps a class name to a list of the (qualified) occurrences
411 that will be mentioned by the derived code for the class when it is later generated.
412 We don't need to put in things that are WiredIn (because they are already mapped to their
413 correct name by the @NameSupply@. The class itself, and all its class ops, is
414 already flagged as an occurrence so we don't need to mention that either.
416 @derivingOccurrences@ has an item for every derivable class, even if that item is empty,
417 because we treat lookup failure as indicating that the class is illegal in a deriving clause.
420 derivingOccurrences :: UniqFM [RdrName]
421 derivingOccurrences = listToUFM deriving_occ_info
423 derivableClassKeys = map fst deriving_occ_info
426 = [ (eqClassKey, [intType_RDR, and_RDR, not_RDR])
427 , (ordClassKey, [intType_RDR, compose_RDR])
428 , (enumClassKey, [intType_RDR, map_RDR])
429 , (evalClassKey, [intType_RDR])
430 , (boundedClassKey, [intType_RDR])
431 , (showClassKey, [intType_RDR, numClass_RDR, ordClass_RDR, compose_RDR, showString_RDR,
432 showParen_RDR, showSpace_RDR, showList___RDR])
433 , (readClassKey, [intType_RDR, numClass_RDR, ordClass_RDR, append_RDR,
434 lex_RDR, readParen_RDR, readList___RDR])
435 , (ixClassKey, [intType_RDR, numClass_RDR, and_RDR, map_RDR])
437 -- intType: Practically any deriving needs Int, either for index calculations,
439 -- ordClass: really it's the methods that are actually used.
440 -- numClass: for Int literals
444 NOTE: @Eq@ and @Text@ do need to appear in @standardClasses@
445 even though every numeric class has these two as a superclass,
446 because the list of ambiguous dictionaries hasn't been simplified.
449 isCcallishClass, isNoDictClass, isNumericClass, isStandardClass :: Class -> Bool
451 isNumericClass clas = classKey clas `is_elem` numericClassKeys
452 isStandardClass clas = classKey clas `is_elem` standardClassKeys
453 isCcallishClass clas = classKey clas `is_elem` cCallishClassKeys
454 isNoDictClass clas = classKey clas `is_elem` noDictClassKeys
455 is_elem = isIn "is_X_Class"
467 needsDataDeclCtxtClassKeys -- see comments in TcDeriv
471 cCallishClassKeys = [ cCallableClassKey, cReturnableClassKey ]
474 = derivableClassKeys ++ numericClassKeys ++ cCallishClassKeys
476 -- We have to have "CCallable" and "CReturnable" in the standard
477 -- classes, so that if you go...
479 -- _ccall_ foo ... 93{-numeric literal-} ...
481 -- ... it can do The Right Thing on the 93.
483 noDictClassKeys -- These classes are used only for type annotations;
484 -- they are not implemented by dictionaries, ever.
486 -- I used to think that class Eval belonged in here, but
487 -- we really want functions with type (Eval a => ...) and that
488 -- means that we really want to pass a placeholder for an Eval
489 -- dictionary. The unit tuple is what we'll get if we leave things
490 -- alone, and that'll do for now. Could arrange to drop that parameter