2 % (c) The AQUA Project, Glasgow University, 1994-1998
6 \section[TysPrim]{Wired-in knowledge about primitive types}
9 -- | This module defines TyCons that can't be expressed in Haskell.
10 -- They are all, therefore, wired-in TyCons. C.f module TysWiredIn
12 alphaTyVars, betaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar,
13 alphaTy, betaTy, gammaTy, deltaTy, ecTyVars,
14 openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar, openAlphaTyVars,
15 argAlphaTy, argAlphaTyVar, argBetaTy, argBetaTyVar,
17 -- Kind constructors...
18 tySuperKindTyCon, tySuperKind,
19 liftedTypeKindTyCon, openTypeKindTyCon, unliftedTypeKindTyCon,
20 argTypeKindTyCon, ubxTupleKindTyCon,
22 tySuperKindTyConName, liftedTypeKindTyConName,
23 openTypeKindTyConName, unliftedTypeKindTyConName,
24 ubxTupleKindTyConName, argTypeKindTyConName,
27 liftedTypeKind, unliftedTypeKind, openTypeKind,
28 argTypeKind, ubxTupleKind,
29 mkArrowKind, mkArrowKinds, isCoercionKind,
32 funTyCon, funTyConName,
35 charPrimTyCon, charPrimTy,
36 intPrimTyCon, intPrimTy,
37 wordPrimTyCon, wordPrimTy,
38 addrPrimTyCon, addrPrimTy,
39 floatPrimTyCon, floatPrimTy,
40 doublePrimTyCon, doublePrimTy,
42 statePrimTyCon, mkStatePrimTy,
43 realWorldTyCon, realWorldTy, realWorldStatePrimTy,
45 arrayPrimTyCon, mkArrayPrimTy,
46 byteArrayPrimTyCon, byteArrayPrimTy,
47 mutableArrayPrimTyCon, mkMutableArrayPrimTy,
48 mutableByteArrayPrimTyCon, mkMutableByteArrayPrimTy,
49 mutVarPrimTyCon, mkMutVarPrimTy,
51 mVarPrimTyCon, mkMVarPrimTy,
52 tVarPrimTyCon, mkTVarPrimTy,
53 stablePtrPrimTyCon, mkStablePtrPrimTy,
54 stableNamePrimTyCon, mkStableNamePrimTy,
55 bcoPrimTyCon, bcoPrimTy,
56 weakPrimTyCon, mkWeakPrimTy,
57 threadIdPrimTyCon, threadIdPrimTy,
59 int32PrimTyCon, int32PrimTy,
60 word32PrimTyCon, word32PrimTy,
62 int64PrimTyCon, int64PrimTy,
63 word64PrimTyCon, word64PrimTy,
65 eqPredPrimTyCon, -- ty1 ~ ty2
68 anyTyCon, anyTyConOfKind, anyTypeOfKind
71 #include "HsVersions.h"
73 import Var ( TyVar, mkTyVar )
74 import Name ( Name, BuiltInSyntax(..), mkInternalName, mkWiredInName )
75 import OccName ( mkTcOcc,mkTyVarOccFS, mkTcOccFS )
79 import Unique ( mkAlphaTyVarUnique )
87 %************************************************************************
89 \subsection{Primitive type constructors}
91 %************************************************************************
107 , mutableArrayPrimTyCon
108 , mutableByteArrayPrimTyCon
114 , stableNamePrimTyCon
124 mkPrimTc :: FastString -> Unique -> TyCon -> Name
125 mkPrimTc fs unique tycon
126 = mkWiredInName gHC_PRIM (mkTcOccFS fs)
128 (ATyCon tycon) -- Relevant TyCon
129 UserSyntax -- None are built-in syntax
131 charPrimTyConName, intPrimTyConName, int32PrimTyConName, int64PrimTyConName, wordPrimTyConName, word32PrimTyConName, word64PrimTyConName, addrPrimTyConName, floatPrimTyConName, doublePrimTyConName, statePrimTyConName, realWorldTyConName, arrayPrimTyConName, byteArrayPrimTyConName, mutableArrayPrimTyConName, mutableByteArrayPrimTyConName, mutVarPrimTyConName, mVarPrimTyConName, tVarPrimTyConName, stablePtrPrimTyConName, stableNamePrimTyConName, bcoPrimTyConName, weakPrimTyConName, threadIdPrimTyConName, eqPredPrimTyConName :: Name
132 charPrimTyConName = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon
133 intPrimTyConName = mkPrimTc (fsLit "Int#") intPrimTyConKey intPrimTyCon
134 int32PrimTyConName = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon
135 int64PrimTyConName = mkPrimTc (fsLit "Int64#") int64PrimTyConKey int64PrimTyCon
136 wordPrimTyConName = mkPrimTc (fsLit "Word#") wordPrimTyConKey wordPrimTyCon
137 word32PrimTyConName = mkPrimTc (fsLit "Word32#") word32PrimTyConKey word32PrimTyCon
138 word64PrimTyConName = mkPrimTc (fsLit "Word64#") word64PrimTyConKey word64PrimTyCon
139 addrPrimTyConName = mkPrimTc (fsLit "Addr#") addrPrimTyConKey addrPrimTyCon
140 floatPrimTyConName = mkPrimTc (fsLit "Float#") floatPrimTyConKey floatPrimTyCon
141 doublePrimTyConName = mkPrimTc (fsLit "Double#") doublePrimTyConKey doublePrimTyCon
142 statePrimTyConName = mkPrimTc (fsLit "State#") statePrimTyConKey statePrimTyCon
143 eqPredPrimTyConName = mkPrimTc (fsLit "~") eqPredPrimTyConKey eqPredPrimTyCon
144 realWorldTyConName = mkPrimTc (fsLit "RealWorld") realWorldTyConKey realWorldTyCon
145 arrayPrimTyConName = mkPrimTc (fsLit "Array#") arrayPrimTyConKey arrayPrimTyCon
146 byteArrayPrimTyConName = mkPrimTc (fsLit "ByteArray#") byteArrayPrimTyConKey byteArrayPrimTyCon
147 mutableArrayPrimTyConName = mkPrimTc (fsLit "MutableArray#") mutableArrayPrimTyConKey mutableArrayPrimTyCon
148 mutableByteArrayPrimTyConName = mkPrimTc (fsLit "MutableByteArray#") mutableByteArrayPrimTyConKey mutableByteArrayPrimTyCon
149 mutVarPrimTyConName = mkPrimTc (fsLit "MutVar#") mutVarPrimTyConKey mutVarPrimTyCon
150 mVarPrimTyConName = mkPrimTc (fsLit "MVar#") mVarPrimTyConKey mVarPrimTyCon
151 tVarPrimTyConName = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPrimTyCon
152 stablePtrPrimTyConName = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon
153 stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon
154 bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon
155 weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon
156 threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon
159 %************************************************************************
161 \subsection{Support code}
163 %************************************************************************
165 alphaTyVars is a list of type variables for use in templates:
166 ["a", "b", ..., "z", "t1", "t2", ... ]
169 tyVarList :: Kind -> [TyVar]
170 tyVarList kind = [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u)
171 (mkTyVarOccFS (mkFastString name))
174 let name | c <= 'z' = [c]
175 | otherwise = 't':show u
176 where c = chr (u-2 + ord 'a')
179 ecKind = liftedTypeKind `mkArrowKind` (liftedTypeKind `mkArrowKind` liftedTypeKind)
182 ecTyVars = tyVarList ecKind
184 alphaTyVars :: [TyVar]
185 alphaTyVars = tyVarList liftedTypeKind
187 betaTyVars :: [TyVar]
188 betaTyVars = tail alphaTyVars
190 alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar
191 (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars
194 alphaTys = mkTyVarTys alphaTyVars
195 alphaTy, betaTy, gammaTy, deltaTy :: Type
196 (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys
198 -- openAlphaTyVar is prepared to be instantiated
199 -- to a lifted or unlifted type variable. It's used for the
200 -- result type for "error", so that we can have (error Int# "Help")
201 openAlphaTyVars :: [TyVar]
202 openAlphaTyVar, openBetaTyVar :: TyVar
203 openAlphaTyVars@(openAlphaTyVar:openBetaTyVar:_) = tyVarList openTypeKind
205 openAlphaTy, openBetaTy :: Type
206 openAlphaTy = mkTyVarTy openAlphaTyVar
207 openBetaTy = mkTyVarTy openBetaTyVar
209 argAlphaTyVar, argBetaTyVar :: TyVar
210 (argAlphaTyVar : argBetaTyVar : _) = tyVarList argTypeKind
211 argAlphaTy, argBetaTy :: Type
212 argAlphaTy = mkTyVarTy argAlphaTyVar
213 argBetaTy = mkTyVarTy argBetaTyVar
217 %************************************************************************
221 %************************************************************************
225 funTyConName = mkPrimTyConName (fsLit "(->)") funTyConKey funTyCon
228 funTyCon = mkFunTyCon funTyConName (mkArrowKinds [argTypeKind, openTypeKind] liftedTypeKind)
229 -- You might think that (->) should have type (?? -> ? -> *), and you'd be right
230 -- But if we do that we get kind errors when saying
231 -- instance Control.Arrow (->)
232 -- becuase the expected kind is (*->*->*). The trouble is that the
233 -- expected/actual stuff in the unifier does not go contra-variant, whereas
234 -- the kind sub-typing does. Sigh. It really only matters if you use (->) in
235 -- a prefix way, thus: (->) Int# Int#. And this is unusual.
236 -- because they are never in scope in the source
240 %************************************************************************
244 %************************************************************************
247 -- | See "Type#kind_subtyping" for details of the distinction between the 'Kind' 'TyCon's
248 tySuperKindTyCon, liftedTypeKindTyCon,
249 openTypeKindTyCon, unliftedTypeKindTyCon,
250 ubxTupleKindTyCon, argTypeKindTyCon
252 tySuperKindTyConName, liftedTypeKindTyConName,
253 openTypeKindTyConName, unliftedTypeKindTyConName,
254 ubxTupleKindTyConName, argTypeKindTyConName
257 tySuperKindTyCon = mkSuperKindTyCon tySuperKindTyConName
258 liftedTypeKindTyCon = mkKindTyCon liftedTypeKindTyConName tySuperKind
259 openTypeKindTyCon = mkKindTyCon openTypeKindTyConName tySuperKind
260 unliftedTypeKindTyCon = mkKindTyCon unliftedTypeKindTyConName tySuperKind
261 ubxTupleKindTyCon = mkKindTyCon ubxTupleKindTyConName tySuperKind
262 argTypeKindTyCon = mkKindTyCon argTypeKindTyConName tySuperKind
264 --------------------------
265 -- ... and now their names
267 tySuperKindTyConName = mkPrimTyConName (fsLit "BOX") tySuperKindTyConKey tySuperKindTyCon
268 liftedTypeKindTyConName = mkPrimTyConName (fsLit "*") liftedTypeKindTyConKey liftedTypeKindTyCon
269 openTypeKindTyConName = mkPrimTyConName (fsLit "?") openTypeKindTyConKey openTypeKindTyCon
270 unliftedTypeKindTyConName = mkPrimTyConName (fsLit "#") unliftedTypeKindTyConKey unliftedTypeKindTyCon
271 ubxTupleKindTyConName = mkPrimTyConName (fsLit "(#)") ubxTupleKindTyConKey ubxTupleKindTyCon
272 argTypeKindTyConName = mkPrimTyConName (fsLit "??") argTypeKindTyConKey argTypeKindTyCon
274 mkPrimTyConName :: FastString -> Unique -> TyCon -> Name
275 mkPrimTyConName occ key tycon = mkWiredInName gHC_PRIM (mkTcOccFS occ)
279 -- All of the super kinds and kinds are defined in Prim and use BuiltInSyntax,
280 -- because they are never in scope in the source
285 kindTyConType :: TyCon -> Type
286 kindTyConType kind = TyConApp kind []
288 -- | See "Type#kind_subtyping" for details of the distinction between these 'Kind's
289 liftedTypeKind, unliftedTypeKind, openTypeKind, argTypeKind, ubxTupleKind :: Kind
291 liftedTypeKind = kindTyConType liftedTypeKindTyCon
292 unliftedTypeKind = kindTyConType unliftedTypeKindTyCon
293 openTypeKind = kindTyConType openTypeKindTyCon
294 argTypeKind = kindTyConType argTypeKindTyCon
295 ubxTupleKind = kindTyConType ubxTupleKindTyCon
297 -- | Given two kinds @k1@ and @k2@, creates the 'Kind' @k1 -> k2@
298 mkArrowKind :: Kind -> Kind -> Kind
299 mkArrowKind k1 k2 = FunTy k1 k2
301 -- | Iterated application of 'mkArrowKind'
302 mkArrowKinds :: [Kind] -> Kind -> Kind
303 mkArrowKinds arg_kinds result_kind = foldr mkArrowKind result_kind arg_kinds
305 tySuperKind :: SuperKind
306 tySuperKind = kindTyConType tySuperKindTyCon
309 %************************************************************************
311 \subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
313 %************************************************************************
317 pcPrimTyCon :: Name -> Int -> PrimRep -> TyCon
318 pcPrimTyCon name arity rep
319 = mkPrimTyCon name kind arity rep
321 kind = mkArrowKinds (replicate arity liftedTypeKind) result_kind
322 result_kind = unliftedTypeKind
324 pcPrimTyCon0 :: Name -> PrimRep -> TyCon
325 pcPrimTyCon0 name rep
326 = mkPrimTyCon name result_kind 0 rep
328 result_kind = unliftedTypeKind
331 charPrimTy = mkTyConTy charPrimTyCon
332 charPrimTyCon :: TyCon
333 charPrimTyCon = pcPrimTyCon0 charPrimTyConName WordRep
336 intPrimTy = mkTyConTy intPrimTyCon
337 intPrimTyCon :: TyCon
338 intPrimTyCon = pcPrimTyCon0 intPrimTyConName IntRep
341 int32PrimTy = mkTyConTy int32PrimTyCon
342 int32PrimTyCon :: TyCon
343 int32PrimTyCon = pcPrimTyCon0 int32PrimTyConName IntRep
346 int64PrimTy = mkTyConTy int64PrimTyCon
347 int64PrimTyCon :: TyCon
348 int64PrimTyCon = pcPrimTyCon0 int64PrimTyConName Int64Rep
351 wordPrimTy = mkTyConTy wordPrimTyCon
352 wordPrimTyCon :: TyCon
353 wordPrimTyCon = pcPrimTyCon0 wordPrimTyConName WordRep
356 word32PrimTy = mkTyConTy word32PrimTyCon
357 word32PrimTyCon :: TyCon
358 word32PrimTyCon = pcPrimTyCon0 word32PrimTyConName WordRep
361 word64PrimTy = mkTyConTy word64PrimTyCon
362 word64PrimTyCon :: TyCon
363 word64PrimTyCon = pcPrimTyCon0 word64PrimTyConName Word64Rep
366 addrPrimTy = mkTyConTy addrPrimTyCon
367 addrPrimTyCon :: TyCon
368 addrPrimTyCon = pcPrimTyCon0 addrPrimTyConName AddrRep
371 floatPrimTy = mkTyConTy floatPrimTyCon
372 floatPrimTyCon :: TyCon
373 floatPrimTyCon = pcPrimTyCon0 floatPrimTyConName FloatRep
376 doublePrimTy = mkTyConTy doublePrimTyCon
377 doublePrimTyCon :: TyCon
378 doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName DoubleRep
382 %************************************************************************
384 \subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
386 %************************************************************************
390 There is a perfectly ordinary type constructor (~) that represents the type
391 of coercions (which, remember, are values). For example
392 Refl Int :: Int ~ Int
394 Atcually it is not quite "perfectly ordinary" because it is kind-polymorphic:
395 Refl Maybe :: Maybe ~ Maybe
397 So the true kind of (~) :: forall k. k -> k -> #. But we don't have
398 polymorphic kinds (yet). However, (~) really only appears saturated in
399 which case there is no problem in finding the kind of (ty1 ~ ty2). So
400 we check that in CoreLint (and, in an assertion, in Kind.typeKind).
402 Note [The State# TyCon]
403 ~~~~~~~~~~~~~~~~~~~~~~~
404 State# is the primitive, unlifted type of states. It has one type parameter,
410 where s is a type variable. The only purpose of the type parameter is to
411 keep different state threads separate. It is represented by nothing at all.
414 mkStatePrimTy :: Type -> Type
415 mkStatePrimTy ty = mkTyConApp statePrimTyCon [ty]
417 statePrimTyCon :: TyCon -- See Note [The State# TyCon]
418 statePrimTyCon = pcPrimTyCon statePrimTyConName 1 VoidRep
420 eqPredPrimTyCon :: TyCon -- The representation type for equality predicates
421 -- See Note [The (~) TyCon]
422 eqPredPrimTyCon = pcPrimTyCon eqPredPrimTyConName 2 VoidRep
425 RealWorld is deeply magical. It is *primitive*, but it is not
426 *unlifted* (hence ptrArg). We never manipulate values of type
427 RealWorld; it's only used in the type system, to parameterise State#.
430 realWorldTyCon :: TyCon
431 realWorldTyCon = mkLiftedPrimTyCon realWorldTyConName liftedTypeKind 0 PtrRep
433 realWorldTy = mkTyConTy realWorldTyCon
434 realWorldStatePrimTy :: Type
435 realWorldStatePrimTy = mkStatePrimTy realWorldTy -- State# RealWorld
438 Note: the ``state-pairing'' types are not truly primitive, so they are
439 defined in \tr{TysWiredIn.lhs}, not here.
441 %************************************************************************
443 \subsection[TysPrim-arrays]{The primitive array types}
445 %************************************************************************
448 arrayPrimTyCon, mutableArrayPrimTyCon, mutableByteArrayPrimTyCon,
449 byteArrayPrimTyCon :: TyCon
450 arrayPrimTyCon = pcPrimTyCon arrayPrimTyConName 1 PtrRep
451 mutableArrayPrimTyCon = pcPrimTyCon mutableArrayPrimTyConName 2 PtrRep
452 mutableByteArrayPrimTyCon = pcPrimTyCon mutableByteArrayPrimTyConName 1 PtrRep
453 byteArrayPrimTyCon = pcPrimTyCon0 byteArrayPrimTyConName PtrRep
455 mkArrayPrimTy :: Type -> Type
456 mkArrayPrimTy elt = mkTyConApp arrayPrimTyCon [elt]
457 byteArrayPrimTy :: Type
458 byteArrayPrimTy = mkTyConTy byteArrayPrimTyCon
459 mkMutableArrayPrimTy :: Type -> Type -> Type
460 mkMutableArrayPrimTy s elt = mkTyConApp mutableArrayPrimTyCon [s, elt]
461 mkMutableByteArrayPrimTy :: Type -> Type
462 mkMutableByteArrayPrimTy s = mkTyConApp mutableByteArrayPrimTyCon [s]
465 %************************************************************************
467 \subsection[TysPrim-mut-var]{The mutable variable type}
469 %************************************************************************
472 mutVarPrimTyCon :: TyCon
473 mutVarPrimTyCon = pcPrimTyCon mutVarPrimTyConName 2 PtrRep
475 mkMutVarPrimTy :: Type -> Type -> Type
476 mkMutVarPrimTy s elt = mkTyConApp mutVarPrimTyCon [s, elt]
479 %************************************************************************
481 \subsection[TysPrim-synch-var]{The synchronizing variable type}
483 %************************************************************************
486 mVarPrimTyCon :: TyCon
487 mVarPrimTyCon = pcPrimTyCon mVarPrimTyConName 2 PtrRep
489 mkMVarPrimTy :: Type -> Type -> Type
490 mkMVarPrimTy s elt = mkTyConApp mVarPrimTyCon [s, elt]
493 %************************************************************************
495 \subsection[TysPrim-stm-var]{The transactional variable type}
497 %************************************************************************
500 tVarPrimTyCon :: TyCon
501 tVarPrimTyCon = pcPrimTyCon tVarPrimTyConName 2 PtrRep
503 mkTVarPrimTy :: Type -> Type -> Type
504 mkTVarPrimTy s elt = mkTyConApp tVarPrimTyCon [s, elt]
507 %************************************************************************
509 \subsection[TysPrim-stable-ptrs]{The stable-pointer type}
511 %************************************************************************
514 stablePtrPrimTyCon :: TyCon
515 stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConName 1 AddrRep
517 mkStablePtrPrimTy :: Type -> Type
518 mkStablePtrPrimTy ty = mkTyConApp stablePtrPrimTyCon [ty]
521 %************************************************************************
523 \subsection[TysPrim-stable-names]{The stable-name type}
525 %************************************************************************
528 stableNamePrimTyCon :: TyCon
529 stableNamePrimTyCon = pcPrimTyCon stableNamePrimTyConName 1 PtrRep
531 mkStableNamePrimTy :: Type -> Type
532 mkStableNamePrimTy ty = mkTyConApp stableNamePrimTyCon [ty]
535 %************************************************************************
537 \subsection[TysPrim-BCOs]{The ``bytecode object'' type}
539 %************************************************************************
543 bcoPrimTy = mkTyConTy bcoPrimTyCon
544 bcoPrimTyCon :: TyCon
545 bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName PtrRep
548 %************************************************************************
550 \subsection[TysPrim-Weak]{The ``weak pointer'' type}
552 %************************************************************************
555 weakPrimTyCon :: TyCon
556 weakPrimTyCon = pcPrimTyCon weakPrimTyConName 1 PtrRep
558 mkWeakPrimTy :: Type -> Type
559 mkWeakPrimTy v = mkTyConApp weakPrimTyCon [v]
562 %************************************************************************
564 \subsection[TysPrim-thread-ids]{The ``thread id'' type}
566 %************************************************************************
568 A thread id is represented by a pointer to the TSO itself, to ensure
569 that they are always unique and we can always find the TSO for a given
570 thread id. However, this has the unfortunate consequence that a
571 ThreadId# for a given thread is treated as a root by the garbage
572 collector and can keep TSOs around for too long.
574 Hence the programmer API for thread manipulation uses a weak pointer
575 to the thread id internally.
578 threadIdPrimTy :: Type
579 threadIdPrimTy = mkTyConTy threadIdPrimTyCon
580 threadIdPrimTyCon :: TyCon
581 threadIdPrimTyCon = pcPrimTyCon0 threadIdPrimTyConName PtrRep
586 %************************************************************************
590 %************************************************************************
594 The type constructor Any::* has these properties
596 * It is defined in module GHC.Prim, and exported so that it is
597 available to users. For this reason it's treated like any other
599 - has a fixed unique, anyTyConKey,
600 - lives in the global name cache
601 - built with TyCon.PrimTyCon
603 * It is lifted, and hence represented by a pointer
605 * It is inhabited by at least one value, namely bottom
607 * You can unsafely coerce any lifted type to Ayny, and back.
609 * It does not claim to be a *data* type, and that's important for
610 the code generator, because the code gen may *enter* a data value
611 but never enters a function value.
613 * It is used to instantiate otherwise un-constrained type variables of kind *
614 For example length Any []
615 See Note [Strangely-kinded void TyCons]
617 In addition, we have a potentially-infinite family of types, one for
618 each kind /other than/ *, needed to instantiate otherwise
619 un-constrained type variables of kinds other than *. This is a bit
620 like tuples; there is a potentially-infinite family. They have slightly
621 different characteristics to Any::*:
623 * They are built with TyCon.AnyTyCon
624 * They have non-user-writable names like "Any(*->*)"
625 * They are not exported by GHC.Prim
626 * They are uninhabited (of course; not kind *)
627 * They have a unique derived from their OccName (see Note [Uniques of Any])
628 * Their Names do not live in the global name cache
630 Note [Uniques of Any]
631 ~~~~~~~~~~~~~~~~~~~~~
632 Although Any(*->*), say, doesn't have a binding site, it still needs
633 to have a Unique. Unlike tuples (which are also an infinite family)
634 there is no convenient way to index them, so we use the Unique from
635 their OccName instead. That should be unique,
636 - both wrt each other, because their strings differ
638 - and wrt any other Name, because Names get uniques with
639 various 'char' tags, but the OccName of Any will
640 get a Unique built with mkTcOccUnique, which has a particular 'char'
641 tag; see Unique.mkTcOccUnique!
643 Note [Strangely-kinded void TyCons]
644 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
645 See Trac #959 for more examples
647 When the type checker finds a type variable with no binding, which
648 means it can be instantiated with an arbitrary type, it usually
649 instantiates it to Void. Eg.
655 But in really obscure programs, the type variable might have a kind
656 other than *, so we need to invent a suitably-kinded type.
660 Any(*->*) for kind *->*
665 anyTyConName = mkPrimTc (fsLit "Any") anyTyConKey anyTyCon
668 anyTyCon = mkLiftedPrimTyCon anyTyConName liftedTypeKind 0 PtrRep
670 anyTypeOfKind :: Kind -> Type
671 anyTypeOfKind kind = mkTyConApp (anyTyConOfKind kind) []
673 anyTyConOfKind :: Kind -> TyCon
674 -- Map all superkinds of liftedTypeKind to liftedTypeKind
676 | isLiftedTypeKind kind = anyTyCon
679 -- Derive the name from the kind, thus:
680 -- Any(*->*), Any(*->*->*)
681 -- These are names that can't be written by the user,
682 -- and are not allocated in the global name cache
683 str = "Any" ++ showSDoc (pprParendKind kind)
686 uniq = getUnique occ -- See Note [Uniques of Any]
687 name = mkWiredInName gHC_PRIM occ uniq (ATyCon tycon) UserSyntax
688 tycon = mkAnyTyCon name kind