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,
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,
31 funTyCon, funTyConName,
34 charPrimTyCon, charPrimTy,
35 intPrimTyCon, intPrimTy,
36 wordPrimTyCon, wordPrimTy,
37 addrPrimTyCon, addrPrimTy,
38 floatPrimTyCon, floatPrimTy,
39 doublePrimTyCon, doublePrimTy,
41 statePrimTyCon, mkStatePrimTy,
42 realWorldTyCon, realWorldTy, realWorldStatePrimTy,
44 arrayPrimTyCon, mkArrayPrimTy,
45 byteArrayPrimTyCon, byteArrayPrimTy,
46 mutableArrayPrimTyCon, mkMutableArrayPrimTy,
47 mutableByteArrayPrimTyCon, mkMutableByteArrayPrimTy,
48 mutVarPrimTyCon, mkMutVarPrimTy,
50 mVarPrimTyCon, mkMVarPrimTy,
51 tVarPrimTyCon, mkTVarPrimTy,
52 stablePtrPrimTyCon, mkStablePtrPrimTy,
53 stableNamePrimTyCon, mkStableNamePrimTy,
54 bcoPrimTyCon, bcoPrimTy,
55 weakPrimTyCon, mkWeakPrimTy,
56 threadIdPrimTyCon, threadIdPrimTy,
58 int32PrimTyCon, int32PrimTy,
59 word32PrimTyCon, word32PrimTy,
61 int64PrimTyCon, int64PrimTy,
62 word64PrimTyCon, word64PrimTy,
64 eqPredPrimTyCon, -- ty1 ~ ty2
67 anyTyCon, anyTyConOfKind, anyTypeOfKind
70 #include "HsVersions.h"
72 import Var ( TyVar, mkTyVar )
73 import Name ( Name, BuiltInSyntax(..), mkInternalName, mkWiredInName )
74 import OccName ( mkTcOcc,mkTyVarOccFS, mkTcOccFS )
78 import Unique ( mkAlphaTyVarUnique )
86 %************************************************************************
88 \subsection{Primitive type constructors}
90 %************************************************************************
106 , mutableArrayPrimTyCon
107 , mutableByteArrayPrimTyCon
113 , stableNamePrimTyCon
123 mkPrimTc :: FastString -> Unique -> TyCon -> Name
124 mkPrimTc fs unique tycon
125 = mkWiredInName gHC_PRIM (mkTcOccFS fs)
127 (ATyCon tycon) -- Relevant TyCon
128 UserSyntax -- None are built-in syntax
130 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
131 charPrimTyConName = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon
132 intPrimTyConName = mkPrimTc (fsLit "Int#") intPrimTyConKey intPrimTyCon
133 int32PrimTyConName = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon
134 int64PrimTyConName = mkPrimTc (fsLit "Int64#") int64PrimTyConKey int64PrimTyCon
135 wordPrimTyConName = mkPrimTc (fsLit "Word#") wordPrimTyConKey wordPrimTyCon
136 word32PrimTyConName = mkPrimTc (fsLit "Word32#") word32PrimTyConKey word32PrimTyCon
137 word64PrimTyConName = mkPrimTc (fsLit "Word64#") word64PrimTyConKey word64PrimTyCon
138 addrPrimTyConName = mkPrimTc (fsLit "Addr#") addrPrimTyConKey addrPrimTyCon
139 floatPrimTyConName = mkPrimTc (fsLit "Float#") floatPrimTyConKey floatPrimTyCon
140 doublePrimTyConName = mkPrimTc (fsLit "Double#") doublePrimTyConKey doublePrimTyCon
141 statePrimTyConName = mkPrimTc (fsLit "State#") statePrimTyConKey statePrimTyCon
142 eqPredPrimTyConName = mkPrimTc (fsLit "~") eqPredPrimTyConKey eqPredPrimTyCon
143 realWorldTyConName = mkPrimTc (fsLit "RealWorld") realWorldTyConKey realWorldTyCon
144 arrayPrimTyConName = mkPrimTc (fsLit "Array#") arrayPrimTyConKey arrayPrimTyCon
145 byteArrayPrimTyConName = mkPrimTc (fsLit "ByteArray#") byteArrayPrimTyConKey byteArrayPrimTyCon
146 mutableArrayPrimTyConName = mkPrimTc (fsLit "MutableArray#") mutableArrayPrimTyConKey mutableArrayPrimTyCon
147 mutableByteArrayPrimTyConName = mkPrimTc (fsLit "MutableByteArray#") mutableByteArrayPrimTyConKey mutableByteArrayPrimTyCon
148 mutVarPrimTyConName = mkPrimTc (fsLit "MutVar#") mutVarPrimTyConKey mutVarPrimTyCon
149 mVarPrimTyConName = mkPrimTc (fsLit "MVar#") mVarPrimTyConKey mVarPrimTyCon
150 tVarPrimTyConName = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPrimTyCon
151 stablePtrPrimTyConName = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon
152 stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon
153 bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon
154 weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon
155 threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon
158 %************************************************************************
160 \subsection{Support code}
162 %************************************************************************
164 alphaTyVars is a list of type variables for use in templates:
165 ["a", "b", ..., "z", "t1", "t2", ... ]
168 tyVarList :: Kind -> [TyVar]
169 tyVarList kind = [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u)
170 (mkTyVarOccFS (mkFastString name))
173 let name | c <= 'z' = [c]
174 | otherwise = 't':show u
175 where c = chr (u-2 + ord 'a')
178 alphaTyVars :: [TyVar]
179 alphaTyVars = tyVarList liftedTypeKind
181 betaTyVars :: [TyVar]
182 betaTyVars = tail alphaTyVars
184 alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar
185 (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars
188 alphaTys = mkTyVarTys alphaTyVars
189 alphaTy, betaTy, gammaTy, deltaTy :: Type
190 (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys
192 -- openAlphaTyVar is prepared to be instantiated
193 -- to a lifted or unlifted type variable. It's used for the
194 -- result type for "error", so that we can have (error Int# "Help")
195 openAlphaTyVars :: [TyVar]
196 openAlphaTyVar, openBetaTyVar :: TyVar
197 openAlphaTyVars@(openAlphaTyVar:openBetaTyVar:_) = tyVarList openTypeKind
199 openAlphaTy, openBetaTy :: Type
200 openAlphaTy = mkTyVarTy openAlphaTyVar
201 openBetaTy = mkTyVarTy openBetaTyVar
203 argAlphaTyVar, argBetaTyVar :: TyVar
204 (argAlphaTyVar : argBetaTyVar : _) = tyVarList argTypeKind
205 argAlphaTy, argBetaTy :: Type
206 argAlphaTy = mkTyVarTy argAlphaTyVar
207 argBetaTy = mkTyVarTy argBetaTyVar
211 %************************************************************************
215 %************************************************************************
219 funTyConName = mkPrimTyConName (fsLit "(->)") funTyConKey funTyCon
222 funTyCon = mkFunTyCon funTyConName (mkArrowKinds [argTypeKind, openTypeKind] liftedTypeKind)
223 -- You might think that (->) should have type (?? -> ? -> *), and you'd be right
224 -- But if we do that we get kind errors when saying
225 -- instance Control.Arrow (->)
226 -- becuase the expected kind is (*->*->*). The trouble is that the
227 -- expected/actual stuff in the unifier does not go contra-variant, whereas
228 -- the kind sub-typing does. Sigh. It really only matters if you use (->) in
229 -- a prefix way, thus: (->) Int# Int#. And this is unusual.
230 -- because they are never in scope in the source
234 %************************************************************************
238 %************************************************************************
241 -- | See "Type#kind_subtyping" for details of the distinction between the 'Kind' 'TyCon's
242 tySuperKindTyCon, liftedTypeKindTyCon,
243 openTypeKindTyCon, unliftedTypeKindTyCon,
244 ubxTupleKindTyCon, argTypeKindTyCon
246 tySuperKindTyConName, liftedTypeKindTyConName,
247 openTypeKindTyConName, unliftedTypeKindTyConName,
248 ubxTupleKindTyConName, argTypeKindTyConName
251 tySuperKindTyCon = mkSuperKindTyCon tySuperKindTyConName
252 liftedTypeKindTyCon = mkKindTyCon liftedTypeKindTyConName tySuperKind
253 openTypeKindTyCon = mkKindTyCon openTypeKindTyConName tySuperKind
254 unliftedTypeKindTyCon = mkKindTyCon unliftedTypeKindTyConName tySuperKind
255 ubxTupleKindTyCon = mkKindTyCon ubxTupleKindTyConName tySuperKind
256 argTypeKindTyCon = mkKindTyCon argTypeKindTyConName tySuperKind
258 --------------------------
259 -- ... and now their names
261 tySuperKindTyConName = mkPrimTyConName (fsLit "BOX") tySuperKindTyConKey tySuperKindTyCon
262 liftedTypeKindTyConName = mkPrimTyConName (fsLit "*") liftedTypeKindTyConKey liftedTypeKindTyCon
263 openTypeKindTyConName = mkPrimTyConName (fsLit "?") openTypeKindTyConKey openTypeKindTyCon
264 unliftedTypeKindTyConName = mkPrimTyConName (fsLit "#") unliftedTypeKindTyConKey unliftedTypeKindTyCon
265 ubxTupleKindTyConName = mkPrimTyConName (fsLit "(#)") ubxTupleKindTyConKey ubxTupleKindTyCon
266 argTypeKindTyConName = mkPrimTyConName (fsLit "??") argTypeKindTyConKey argTypeKindTyCon
268 mkPrimTyConName :: FastString -> Unique -> TyCon -> Name
269 mkPrimTyConName occ key tycon = mkWiredInName gHC_PRIM (mkTcOccFS occ)
273 -- All of the super kinds and kinds are defined in Prim and use BuiltInSyntax,
274 -- because they are never in scope in the source
279 kindTyConType :: TyCon -> Type
280 kindTyConType kind = TyConApp kind []
282 -- | See "Type#kind_subtyping" for details of the distinction between these 'Kind's
283 liftedTypeKind, unliftedTypeKind, openTypeKind, argTypeKind, ubxTupleKind :: Kind
285 liftedTypeKind = kindTyConType liftedTypeKindTyCon
286 unliftedTypeKind = kindTyConType unliftedTypeKindTyCon
287 openTypeKind = kindTyConType openTypeKindTyCon
288 argTypeKind = kindTyConType argTypeKindTyCon
289 ubxTupleKind = kindTyConType ubxTupleKindTyCon
291 -- | Given two kinds @k1@ and @k2@, creates the 'Kind' @k1 -> k2@
292 mkArrowKind :: Kind -> Kind -> Kind
293 mkArrowKind k1 k2 = FunTy k1 k2
295 -- | Iterated application of 'mkArrowKind'
296 mkArrowKinds :: [Kind] -> Kind -> Kind
297 mkArrowKinds arg_kinds result_kind = foldr mkArrowKind result_kind arg_kinds
299 tySuperKind :: SuperKind
300 tySuperKind = kindTyConType tySuperKindTyCon
303 %************************************************************************
305 \subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
307 %************************************************************************
311 pcPrimTyCon :: Name -> Int -> PrimRep -> TyCon
312 pcPrimTyCon name arity rep
313 = mkPrimTyCon name kind arity rep
315 kind = mkArrowKinds (replicate arity liftedTypeKind) result_kind
316 result_kind = unliftedTypeKind
318 pcPrimTyCon0 :: Name -> PrimRep -> TyCon
319 pcPrimTyCon0 name rep
320 = mkPrimTyCon name result_kind 0 rep
322 result_kind = unliftedTypeKind
325 charPrimTy = mkTyConTy charPrimTyCon
326 charPrimTyCon :: TyCon
327 charPrimTyCon = pcPrimTyCon0 charPrimTyConName WordRep
330 intPrimTy = mkTyConTy intPrimTyCon
331 intPrimTyCon :: TyCon
332 intPrimTyCon = pcPrimTyCon0 intPrimTyConName IntRep
335 int32PrimTy = mkTyConTy int32PrimTyCon
336 int32PrimTyCon :: TyCon
337 int32PrimTyCon = pcPrimTyCon0 int32PrimTyConName IntRep
340 int64PrimTy = mkTyConTy int64PrimTyCon
341 int64PrimTyCon :: TyCon
342 int64PrimTyCon = pcPrimTyCon0 int64PrimTyConName Int64Rep
345 wordPrimTy = mkTyConTy wordPrimTyCon
346 wordPrimTyCon :: TyCon
347 wordPrimTyCon = pcPrimTyCon0 wordPrimTyConName WordRep
350 word32PrimTy = mkTyConTy word32PrimTyCon
351 word32PrimTyCon :: TyCon
352 word32PrimTyCon = pcPrimTyCon0 word32PrimTyConName WordRep
355 word64PrimTy = mkTyConTy word64PrimTyCon
356 word64PrimTyCon :: TyCon
357 word64PrimTyCon = pcPrimTyCon0 word64PrimTyConName Word64Rep
360 addrPrimTy = mkTyConTy addrPrimTyCon
361 addrPrimTyCon :: TyCon
362 addrPrimTyCon = pcPrimTyCon0 addrPrimTyConName AddrRep
365 floatPrimTy = mkTyConTy floatPrimTyCon
366 floatPrimTyCon :: TyCon
367 floatPrimTyCon = pcPrimTyCon0 floatPrimTyConName FloatRep
370 doublePrimTy = mkTyConTy doublePrimTyCon
371 doublePrimTyCon :: TyCon
372 doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName DoubleRep
376 %************************************************************************
378 \subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
380 %************************************************************************
384 There is a perfectly ordinary type constructor (~) that represents the type
385 of coercions (which, remember, are values). For example
386 Refl Int :: Int ~ Int
388 Atcually it is not quite "perfectly ordinary" because it is kind-polymorphic:
389 Refl Maybe :: Maybe ~ Maybe
391 So the true kind of (~) :: forall k. k -> k -> #. But we don't have
392 polymorphic kinds (yet). However, (~) really only appears saturated in
393 which case there is no problem in finding the kind of (ty1 ~ ty2). So
394 we check that in CoreLint (and, in an assertion, in Kind.typeKind).
396 Note [The State# TyCon]
397 ~~~~~~~~~~~~~~~~~~~~~~~
398 State# is the primitive, unlifted type of states. It has one type parameter,
404 where s is a type variable. The only purpose of the type parameter is to
405 keep different state threads separate. It is represented by nothing at all.
408 mkStatePrimTy :: Type -> Type
409 mkStatePrimTy ty = mkTyConApp statePrimTyCon [ty]
411 statePrimTyCon :: TyCon -- See Note [The State# TyCon]
412 statePrimTyCon = pcPrimTyCon statePrimTyConName 1 VoidRep
414 eqPredPrimTyCon :: TyCon -- The representation type for equality predicates
415 -- See Note [The (~) TyCon]
416 eqPredPrimTyCon = pcPrimTyCon eqPredPrimTyConName 2 VoidRep
419 RealWorld is deeply magical. It is *primitive*, but it is not
420 *unlifted* (hence ptrArg). We never manipulate values of type
421 RealWorld; it's only used in the type system, to parameterise State#.
424 realWorldTyCon :: TyCon
425 realWorldTyCon = mkLiftedPrimTyCon realWorldTyConName liftedTypeKind 0 PtrRep
427 realWorldTy = mkTyConTy realWorldTyCon
428 realWorldStatePrimTy :: Type
429 realWorldStatePrimTy = mkStatePrimTy realWorldTy -- State# RealWorld
432 Note: the ``state-pairing'' types are not truly primitive, so they are
433 defined in \tr{TysWiredIn.lhs}, not here.
435 %************************************************************************
437 \subsection[TysPrim-arrays]{The primitive array types}
439 %************************************************************************
442 arrayPrimTyCon, mutableArrayPrimTyCon, mutableByteArrayPrimTyCon,
443 byteArrayPrimTyCon :: TyCon
444 arrayPrimTyCon = pcPrimTyCon arrayPrimTyConName 1 PtrRep
445 mutableArrayPrimTyCon = pcPrimTyCon mutableArrayPrimTyConName 2 PtrRep
446 mutableByteArrayPrimTyCon = pcPrimTyCon mutableByteArrayPrimTyConName 1 PtrRep
447 byteArrayPrimTyCon = pcPrimTyCon0 byteArrayPrimTyConName PtrRep
449 mkArrayPrimTy :: Type -> Type
450 mkArrayPrimTy elt = mkTyConApp arrayPrimTyCon [elt]
451 byteArrayPrimTy :: Type
452 byteArrayPrimTy = mkTyConTy byteArrayPrimTyCon
453 mkMutableArrayPrimTy :: Type -> Type -> Type
454 mkMutableArrayPrimTy s elt = mkTyConApp mutableArrayPrimTyCon [s, elt]
455 mkMutableByteArrayPrimTy :: Type -> Type
456 mkMutableByteArrayPrimTy s = mkTyConApp mutableByteArrayPrimTyCon [s]
459 %************************************************************************
461 \subsection[TysPrim-mut-var]{The mutable variable type}
463 %************************************************************************
466 mutVarPrimTyCon :: TyCon
467 mutVarPrimTyCon = pcPrimTyCon mutVarPrimTyConName 2 PtrRep
469 mkMutVarPrimTy :: Type -> Type -> Type
470 mkMutVarPrimTy s elt = mkTyConApp mutVarPrimTyCon [s, elt]
473 %************************************************************************
475 \subsection[TysPrim-synch-var]{The synchronizing variable type}
477 %************************************************************************
480 mVarPrimTyCon :: TyCon
481 mVarPrimTyCon = pcPrimTyCon mVarPrimTyConName 2 PtrRep
483 mkMVarPrimTy :: Type -> Type -> Type
484 mkMVarPrimTy s elt = mkTyConApp mVarPrimTyCon [s, elt]
487 %************************************************************************
489 \subsection[TysPrim-stm-var]{The transactional variable type}
491 %************************************************************************
494 tVarPrimTyCon :: TyCon
495 tVarPrimTyCon = pcPrimTyCon tVarPrimTyConName 2 PtrRep
497 mkTVarPrimTy :: Type -> Type -> Type
498 mkTVarPrimTy s elt = mkTyConApp tVarPrimTyCon [s, elt]
501 %************************************************************************
503 \subsection[TysPrim-stable-ptrs]{The stable-pointer type}
505 %************************************************************************
508 stablePtrPrimTyCon :: TyCon
509 stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConName 1 AddrRep
511 mkStablePtrPrimTy :: Type -> Type
512 mkStablePtrPrimTy ty = mkTyConApp stablePtrPrimTyCon [ty]
515 %************************************************************************
517 \subsection[TysPrim-stable-names]{The stable-name type}
519 %************************************************************************
522 stableNamePrimTyCon :: TyCon
523 stableNamePrimTyCon = pcPrimTyCon stableNamePrimTyConName 1 PtrRep
525 mkStableNamePrimTy :: Type -> Type
526 mkStableNamePrimTy ty = mkTyConApp stableNamePrimTyCon [ty]
529 %************************************************************************
531 \subsection[TysPrim-BCOs]{The ``bytecode object'' type}
533 %************************************************************************
537 bcoPrimTy = mkTyConTy bcoPrimTyCon
538 bcoPrimTyCon :: TyCon
539 bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName PtrRep
542 %************************************************************************
544 \subsection[TysPrim-Weak]{The ``weak pointer'' type}
546 %************************************************************************
549 weakPrimTyCon :: TyCon
550 weakPrimTyCon = pcPrimTyCon weakPrimTyConName 1 PtrRep
552 mkWeakPrimTy :: Type -> Type
553 mkWeakPrimTy v = mkTyConApp weakPrimTyCon [v]
556 %************************************************************************
558 \subsection[TysPrim-thread-ids]{The ``thread id'' type}
560 %************************************************************************
562 A thread id is represented by a pointer to the TSO itself, to ensure
563 that they are always unique and we can always find the TSO for a given
564 thread id. However, this has the unfortunate consequence that a
565 ThreadId# for a given thread is treated as a root by the garbage
566 collector and can keep TSOs around for too long.
568 Hence the programmer API for thread manipulation uses a weak pointer
569 to the thread id internally.
572 threadIdPrimTy :: Type
573 threadIdPrimTy = mkTyConTy threadIdPrimTyCon
574 threadIdPrimTyCon :: TyCon
575 threadIdPrimTyCon = pcPrimTyCon0 threadIdPrimTyConName PtrRep
580 %************************************************************************
584 %************************************************************************
588 The type constructor Any::* has these properties
590 * It is defined in module GHC.Prim, and exported so that it is
591 available to users. For this reason it's treated like any other
593 - has a fixed unique, anyTyConKey,
594 - lives in the global name cache
595 - built with TyCon.PrimTyCon
597 * It is lifted, and hence represented by a pointer
599 * It is inhabited by at least one value, namely bottom
601 * You can unsafely coerce any lifted type to Ayny, and back.
603 * It does not claim to be a *data* type, and that's important for
604 the code generator, because the code gen may *enter* a data value
605 but never enters a function value.
607 * It is used to instantiate otherwise un-constrained type variables of kind *
608 For example length Any []
609 See Note [Strangely-kinded void TyCons]
611 In addition, we have a potentially-infinite family of types, one for
612 each kind /other than/ *, needed to instantiate otherwise
613 un-constrained type variables of kinds other than *. This is a bit
614 like tuples; there is a potentially-infinite family. They have slightly
615 different characteristics to Any::*:
617 * They are built with TyCon.AnyTyCon
618 * They have non-user-writable names like "Any(*->*)"
619 * They are not exported by GHC.Prim
620 * They are uninhabited (of course; not kind *)
621 * They have a unique derived from their OccName (see Note [Uniques of Any])
622 * Their Names do not live in the global name cache
624 Note [Uniques of Any]
625 ~~~~~~~~~~~~~~~~~~~~~
626 Although Any(*->*), say, doesn't have a binding site, it still needs
627 to have a Unique. Unlike tuples (which are also an infinite family)
628 there is no convenient way to index them, so we use the Unique from
629 their OccName instead. That should be unique,
630 - both wrt each other, because their strings differ
632 - and wrt any other Name, because Names get uniques with
633 various 'char' tags, but the OccName of Any will
634 get a Unique built with mkTcOccUnique, which has a particular 'char'
635 tag; see Unique.mkTcOccUnique!
637 Note [Strangely-kinded void TyCons]
638 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
639 See Trac #959 for more examples
641 When the type checker finds a type variable with no binding, which
642 means it can be instantiated with an arbitrary type, it usually
643 instantiates it to Void. Eg.
649 But in really obscure programs, the type variable might have a kind
650 other than *, so we need to invent a suitably-kinded type.
654 Any(*->*) for kind *->*
659 anyTyConName = mkPrimTc (fsLit "Any") anyTyConKey anyTyCon
662 anyTyCon = mkLiftedPrimTyCon anyTyConName liftedTypeKind 0 PtrRep
664 anyTypeOfKind :: Kind -> Type
665 anyTypeOfKind kind = mkTyConApp (anyTyConOfKind kind) []
667 anyTyConOfKind :: Kind -> TyCon
668 -- Map all superkinds of liftedTypeKind to liftedTypeKind
670 | isLiftedTypeKind kind = anyTyCon
673 -- Derive the name from the kind, thus:
674 -- Any(*->*), Any(*->*->*)
675 -- These are names that can't be written by the user,
676 -- and are not allocated in the global name cache
677 str = "Any" ++ showSDoc (pprParendKind kind)
680 uniq = getUnique occ -- See Note [Uniques of Any]
681 name = mkWiredInName gHC_PRIM occ uniq (ATyCon tycon) UserSyntax
682 tycon = mkAnyTyCon name kind