2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
11 builtinNames, -- Names of things whose *unique* must be known, but
12 -- that is all. If something is in here, you know that
13 -- if it's used at all then it's Name will be just as
14 -- it is here, unique and all. Includes all the
16 derivingOccurrences, -- For a given class C, this tells what other
17 derivableClassKeys, -- things are needed as a result of a
23 eqH_Char_RDR, ltH_Char_RDR, eqH_Word_RDR, ltH_Word_RDR,
24 eqH_Addr_RDR, ltH_Addr_RDR, eqH_Float_RDR, ltH_Float_RDR,
25 eqH_Double_RDR, ltH_Double_RDR, eqH_Int_RDR, ltH_Int_RDR,
26 geH_RDR, leH_RDR, minusH_RDR, tagToEnumH_RDR,
28 -- Random other things
29 maybeCharLikeCon, maybeIntLikeCon,
30 needsDataDeclCtxtClassKeys, cCallishClassKeys, cCallishTyKeys,
31 isNoDictClass, isNumericClass, isStandardClass, isCcallishClass,
32 isCreturnableClass, numericTyKeys, fractionalClassKeys,
36 #include "HsVersions.h"
40 import PrelNames -- Prelude module names
42 import PrimOp ( PrimOp(..), allThePrimOps, primOpRdrName )
43 import DataCon ( DataCon, dataConId, dataConWrapId )
44 import TysPrim -- TYPES
48 import RdrName ( RdrName )
49 import Name ( Name, OccName, Provenance(..),
50 NameSpace, tcName, clsName, varName, dataName,
52 getName, mkGlobalName, nameRdrName
54 import Class ( Class, classKey )
55 import TyCon ( tyConDataConsIfAvailable, TyCon )
56 import Type ( funTyCon )
58 import BasicTypes ( Boxity(..) )
59 import Unique -- *Key stuff
60 import UniqFM ( UniqFM, listToUFM )
64 %************************************************************************
66 \subsection[builtinNameInfo]{Lookup built-in names}
68 %************************************************************************
70 We have two ``builtin name funs,'' one to look up @TyCons@ and
71 @Classes@, the other to look up values.
74 builtinNames :: Bag Name
78 unionManyBags (map getTyConNames wired_in_tycons)
81 , listToBag (map getName wiredInIds)
84 , listToBag (map (getName . mkPrimOpId) allThePrimOps)
86 -- Other names with magic keys
87 , listToBag knownKeyNames
93 getTyConNames :: TyCon -> Bag Name
95 = getName tycon `consBag`
96 unionManyBags (map get_data_con_names (tyConDataConsIfAvailable tycon))
97 -- Synonyms return empty list of constructors
99 get_data_con_names dc = listToBag [getName (dataConId dc), -- Worker
100 getName (dataConWrapId dc)] -- Wrapper
103 We let a lot of "non-standard" values be visible, so that we can make
104 sense of them in interface pragmas. It's cool, though they all have
105 "non-standard" names, so they won't get past the parser in user code.
108 %************************************************************************
110 \subsection{RdrNames for the primops}
112 %************************************************************************
114 These can't be in PrelNames, because we get the RdrName from the PrimOp,
115 which is above PrelNames in the module hierarchy.
118 eqH_Char_RDR = primOpRdrName CharEqOp
119 ltH_Char_RDR = primOpRdrName CharLtOp
120 eqH_Word_RDR = primOpRdrName WordEqOp
121 ltH_Word_RDR = primOpRdrName WordLtOp
122 eqH_Addr_RDR = primOpRdrName AddrEqOp
123 ltH_Addr_RDR = primOpRdrName AddrLtOp
124 eqH_Float_RDR = primOpRdrName FloatEqOp
125 ltH_Float_RDR = primOpRdrName FloatLtOp
126 eqH_Double_RDR = primOpRdrName DoubleEqOp
127 ltH_Double_RDR = primOpRdrName DoubleLtOp
128 eqH_Int_RDR = primOpRdrName IntEqOp
129 ltH_Int_RDR = primOpRdrName IntLtOp
130 geH_RDR = primOpRdrName IntGeOp
131 leH_RDR = primOpRdrName IntLeOp
132 minusH_RDR = primOpRdrName IntSubOp
134 tagToEnumH_RDR = primOpRdrName TagToEnumOp
137 %************************************************************************
139 \subsection{Wired in TyCons}
141 %************************************************************************
144 wired_in_tycons = [funTyCon] ++
147 unboxed_tuple_tycons ++
159 , foreignObjPrimTyCon
161 , mutableArrayPrimTyCon
162 , mutableByteArrayPrimTyCon
167 , stableNamePrimTyCon
174 tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..37] ]
175 unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..37] ]
191 %************************************************************************
193 \subsection{Built-in keys}
195 %************************************************************************
197 Ids, Synonyms, Classes and ClassOps with builtin keys.
200 knownKeyNames :: [Name]
202 = map mkKnownKeyGlobal
204 -- Type constructors (synonyms especially)
205 (ioTyCon_RDR, ioTyConKey)
206 , (main_RDR, mainKey)
207 , (orderingTyCon_RDR, orderingTyConKey)
208 , (rationalTyCon_RDR, rationalTyConKey)
209 , (ratioDataCon_RDR, ratioDataConKey)
210 , (ratioTyCon_RDR, ratioTyConKey)
211 , (byteArrayTyCon_RDR, byteArrayTyConKey)
212 , (mutableByteArrayTyCon_RDR, mutableByteArrayTyConKey)
213 , (foreignObjTyCon_RDR, foreignObjTyConKey)
214 , (stablePtrTyCon_RDR, stablePtrTyConKey)
215 , (stablePtrDataCon_RDR, stablePtrDataConKey)
217 -- Classes. *Must* include:
218 -- classes that are grabbed by key (e.g., eqClassKey)
219 -- classes in "Class.standardClassKeys" (quite a few)
220 , (eqClass_RDR, eqClassKey) -- mentioned, derivable
221 , (ordClass_RDR, ordClassKey) -- derivable
222 , (boundedClass_RDR, boundedClassKey) -- derivable
223 , (numClass_RDR, numClassKey) -- mentioned, numeric
224 , (enumClass_RDR, enumClassKey) -- derivable
225 , (monadClass_RDR, monadClassKey)
226 , (monadPlusClass_RDR, monadPlusClassKey)
227 , (functorClass_RDR, functorClassKey)
228 , (showClass_RDR, showClassKey) -- derivable
229 , (realClass_RDR, realClassKey) -- numeric
230 , (integralClass_RDR, integralClassKey) -- numeric
231 , (fractionalClass_RDR, fractionalClassKey) -- numeric
232 , (floatingClass_RDR, floatingClassKey) -- numeric
233 , (realFracClass_RDR, realFracClassKey) -- numeric
234 , (realFloatClass_RDR, realFloatClassKey) -- numeric
235 , (readClass_RDR, readClassKey) -- derivable
236 , (ixClass_RDR, ixClassKey) -- derivable (but it isn't Prelude.Ix; hmmm)
237 , (ccallableClass_RDR, cCallableClassKey) -- mentioned, ccallish
238 , (creturnableClass_RDR, cReturnableClassKey) -- mentioned, ccallish
241 , (fromInt_RDR, fromIntClassOpKey)
242 , (fromInteger_RDR, fromIntegerClassOpKey)
243 , (ge_RDR, geClassOpKey)
244 , (minus_RDR, minusClassOpKey)
245 , (enumFrom_RDR, enumFromClassOpKey)
246 , (enumFromThen_RDR, enumFromThenClassOpKey)
247 , (enumFromTo_RDR, enumFromToClassOpKey)
248 , (enumFromThenTo_RDR, enumFromThenToClassOpKey)
249 , (fromEnum_RDR, fromEnumClassOpKey)
250 , (toEnum_RDR, toEnumClassOpKey)
251 , (eq_RDR, eqClassOpKey)
252 , (thenM_RDR, thenMClassOpKey)
253 , (returnM_RDR, returnMClassOpKey)
254 , (failM_RDR, failMClassOpKey)
255 , (fromRational_RDR, fromRationalClassOpKey)
257 , (deRefStablePtr_RDR, deRefStablePtrIdKey)
258 , (makeStablePtr_RDR, makeStablePtrIdKey)
259 , (bindIO_RDR, bindIOIdKey)
260 , (returnIO_RDR, returnIOIdKey)
261 , (addr2Integer_RDR, addr2IntegerIdKey)
264 , (map_RDR, mapIdKey)
265 , (append_RDR, appendIdKey)
266 , (unpackCString_RDR, unpackCStringIdKey)
267 , (unpackCString2_RDR, unpackCString2IdKey)
268 , (unpackCStringAppend_RDR, unpackCStringAppendIdKey)
269 , (unpackCStringFoldr_RDR, unpackCStringFoldrIdKey)
272 , (concat_RDR, concatIdKey)
273 , (filter_RDR, filterIdKey)
274 , (zip_RDR, zipIdKey)
275 , (foldr_RDR, foldrIdKey)
276 , (build_RDR, buildIdKey)
277 , (augment_RDR, augmentIdKey)
279 -- FFI primitive types that are not wired-in.
280 , (int8TyCon_RDR, int8TyConKey)
281 , (int16TyCon_RDR, int16TyConKey)
282 , (int32TyCon_RDR, int32TyConKey)
283 , (int64TyCon_RDR, int64TyConKey)
284 , (word8TyCon_RDR, word8TyConKey)
285 , (word16TyCon_RDR, word16TyConKey)
286 , (word32TyCon_RDR, word32TyConKey)
287 , (word64TyCon_RDR, word64TyConKey)
290 , (otherwiseId_RDR, otherwiseIdKey)
291 , (assert_RDR, assertIdKey)
292 , (runSTRep_RDR, runSTRepIdKey)
296 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
299 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
300 maybeCharLikeCon con = con `hasKey` charDataConKey
301 maybeIntLikeCon con = con `hasKey` intDataConKey
304 %************************************************************************
306 \subsection[Class-std-groups]{Standard groups of Prelude classes}
308 %************************************************************************
310 @derivableClassKeys@ is also used in checking \tr{deriving} constructs
313 @derivingOccurrences@ maps a class name to a list of the (qualified) occurrences
314 that will be mentioned by the derived code for the class when it is later generated.
315 We don't need to put in things that are WiredIn (because they are already mapped to their
316 correct name by the @NameSupply@. The class itself, and all its class ops, is
317 already flagged as an occurrence so we don't need to mention that either.
319 @derivingOccurrences@ has an item for every derivable class, even if that item is empty,
320 because we treat lookup failure as indicating that the class is illegal in a deriving clause.
323 derivingOccurrences :: UniqFM [RdrName]
324 derivingOccurrences = listToUFM deriving_occ_info
326 derivableClassKeys = map fst deriving_occ_info
329 = [ (eqClassKey, [intTyCon_RDR, and_RDR, not_RDR])
330 , (ordClassKey, [intTyCon_RDR, compose_RDR, eqTag_RDR])
331 -- EQ (from Ordering) is needed to force in the constructors
332 -- as well as the type constructor.
333 , (enumClassKey, [intTyCon_RDR, eq_RDR, ge_RDR, and_RDR, map_RDR, plus_RDR, showsPrec_RDR, append_RDR])
334 -- The last two Enum deps are only used to produce better
335 -- error msgs for derived toEnum methods.
336 , (boundedClassKey, [intTyCon_RDR])
337 , (showClassKey, [intTyCon_RDR, numClass_RDR, ordClass_RDR, compose_RDR, showString_RDR,
338 showParen_RDR, showSpace_RDR, showList___RDR])
339 , (readClassKey, [intTyCon_RDR, numClass_RDR, ordClass_RDR, append_RDR,
340 foldr_RDR, build_RDR,
341 -- foldr and build required for list comprehension
343 lex_RDR, readParen_RDR, readList___RDR, thenM_RDR])
344 -- returnM (and the rest of the Monad class decl)
345 -- will be forced in as result of depending
346 -- on thenM. -- SOF 1/99
347 , (ixClassKey, [intTyCon_RDR, numClass_RDR, and_RDR, map_RDR, enumFromTo_RDR,
348 foldr_RDR, build_RDR,
349 -- foldr and build required for list comprehension used
350 -- with single constructor types -- KSW 2000-06
351 returnM_RDR, failM_RDR])
352 -- the last two are needed to force returnM, thenM and failM
353 -- in before typechecking the list(monad) comprehension
354 -- generated for derived Ix instances (range method)
355 -- of single constructor types. -- SOF 8/97
357 -- intTyCon: Practically any deriving needs Int, either for index calculations,
359 -- ordClass: really it's the methods that are actually used.
360 -- numClass: for Int literals
364 NOTE: @Eq@ and @Text@ do need to appear in @standardClasses@
365 even though every numeric class has these two as a superclass,
366 because the list of ambiguous dictionaries hasn't been simplified.
369 isCcallishClass, isCreturnableClass, isNoDictClass,
370 isNumericClass, isStandardClass :: Class -> Bool
372 isFractionalClass clas = classKey clas `is_elem` fractionalClassKeys
373 isNumericClass clas = classKey clas `is_elem` numericClassKeys
374 isStandardClass clas = classKey clas `is_elem` standardClassKeys
375 isCcallishClass clas = classKey clas `is_elem` cCallishClassKeys
376 isCreturnableClass clas = classKey clas == cReturnableClassKey
377 isNoDictClass clas = classKey clas `is_elem` noDictClassKeys
378 is_elem = isIn "is_X_Class"
385 ++ fractionalClassKeys
387 fractionalClassKeys =
394 -- the strictness analyser needs to know about numeric types
395 -- (see SaAbsInt.lhs)
405 needsDataDeclCtxtClassKeys = -- see comments in TcDeriv
411 , cReturnableClassKey
414 -- Renamer always imports these data decls replete with constructors
415 -- so that desugarer can always see their constructors. Ugh!
420 , mutableByteArrayTyConKey
434 = derivableClassKeys ++ numericClassKeys ++ cCallishClassKeys
436 -- We have to have "CCallable" and "CReturnable" in the standard
437 -- classes, so that if you go...
439 -- _ccall_ foo ... 93{-numeric literal-} ...
441 -- ... it can do The Right Thing on the 93.
443 noDictClassKeys -- These classes are used only for type annotations;
444 -- they are not implemented by dictionaries, ever.