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,
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 )
80 import Unique ( mkAlphaTyVarUnique )
88 %************************************************************************
90 \subsection{Primitive type constructors}
92 %************************************************************************
108 , mutableArrayPrimTyCon
109 , mutableByteArrayPrimTyCon
115 , stableNamePrimTyCon
125 mkPrimTc :: FastString -> Unique -> TyCon -> Name
126 mkPrimTc fs unique tycon
127 = mkWiredInName gHC_PRIM (mkTcOccFS fs)
129 (ATyCon tycon) -- Relevant TyCon
130 UserSyntax -- None are built-in syntax
132 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
133 charPrimTyConName = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon
134 intPrimTyConName = mkPrimTc (fsLit "Int#") intPrimTyConKey intPrimTyCon
135 int32PrimTyConName = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon
136 int64PrimTyConName = mkPrimTc (fsLit "Int64#") int64PrimTyConKey int64PrimTyCon
137 wordPrimTyConName = mkPrimTc (fsLit "Word#") wordPrimTyConKey wordPrimTyCon
138 word32PrimTyConName = mkPrimTc (fsLit "Word32#") word32PrimTyConKey word32PrimTyCon
139 word64PrimTyConName = mkPrimTc (fsLit "Word64#") word64PrimTyConKey word64PrimTyCon
140 addrPrimTyConName = mkPrimTc (fsLit "Addr#") addrPrimTyConKey addrPrimTyCon
141 floatPrimTyConName = mkPrimTc (fsLit "Float#") floatPrimTyConKey floatPrimTyCon
142 doublePrimTyConName = mkPrimTc (fsLit "Double#") doublePrimTyConKey doublePrimTyCon
143 statePrimTyConName = mkPrimTc (fsLit "State#") statePrimTyConKey statePrimTyCon
144 eqPredPrimTyConName = mkPrimTc (fsLit "~") eqPredPrimTyConKey eqPredPrimTyCon
145 realWorldTyConName = mkPrimTc (fsLit "RealWorld") realWorldTyConKey realWorldTyCon
146 arrayPrimTyConName = mkPrimTc (fsLit "Array#") arrayPrimTyConKey arrayPrimTyCon
147 byteArrayPrimTyConName = mkPrimTc (fsLit "ByteArray#") byteArrayPrimTyConKey byteArrayPrimTyCon
148 mutableArrayPrimTyConName = mkPrimTc (fsLit "MutableArray#") mutableArrayPrimTyConKey mutableArrayPrimTyCon
149 mutableByteArrayPrimTyConName = mkPrimTc (fsLit "MutableByteArray#") mutableByteArrayPrimTyConKey mutableByteArrayPrimTyCon
150 mutVarPrimTyConName = mkPrimTc (fsLit "MutVar#") mutVarPrimTyConKey mutVarPrimTyCon
151 mVarPrimTyConName = mkPrimTc (fsLit "MVar#") mVarPrimTyConKey mVarPrimTyCon
152 tVarPrimTyConName = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPrimTyCon
153 stablePtrPrimTyConName = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon
154 stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon
155 bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon
156 weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon
157 threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon
160 %************************************************************************
162 \subsection{Support code}
164 %************************************************************************
166 alphaTyVars is a list of type variables for use in templates:
167 ["a", "b", ..., "z", "t1", "t2", ... ]
170 tyVarList :: Kind -> [TyVar]
171 tyVarList kind = [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u)
172 (mkTyVarOccFS (mkFastString name))
175 let name | c <= 'z' = [c]
176 | otherwise = 't':show u
177 where c = chr (u-2 + ord 'a')
181 ecTyVars = tyVarList ecKind
183 alphaTyVars :: [TyVar]
184 alphaTyVars = tyVarList liftedTypeKind
186 betaTyVars :: [TyVar]
187 betaTyVars = tail alphaTyVars
189 alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar
190 (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars
193 alphaTys = mkTyVarTys alphaTyVars
194 alphaTy, betaTy, gammaTy, deltaTy :: Type
195 (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys
197 -- openAlphaTyVar is prepared to be instantiated
198 -- to a lifted or unlifted type variable. It's used for the
199 -- result type for "error", so that we can have (error Int# "Help")
200 openAlphaTyVars :: [TyVar]
201 openAlphaTyVar, openBetaTyVar :: TyVar
202 openAlphaTyVars@(openAlphaTyVar:openBetaTyVar:_) = tyVarList openTypeKind
204 openAlphaTy, openBetaTy :: Type
205 openAlphaTy = mkTyVarTy openAlphaTyVar
206 openBetaTy = mkTyVarTy openBetaTyVar
208 argAlphaTyVar, argBetaTyVar :: TyVar
209 (argAlphaTyVar : argBetaTyVar : _) = tyVarList argTypeKind
210 argAlphaTy, argBetaTy :: Type
211 argAlphaTy = mkTyVarTy argAlphaTyVar
212 argBetaTy = mkTyVarTy argBetaTyVar
216 %************************************************************************
220 %************************************************************************
224 funTyConName = mkPrimTyConName (fsLit "(->)") funTyConKey funTyCon
227 funTyCon = mkFunTyCon funTyConName (mkArrowKinds [argTypeKind, openTypeKind] liftedTypeKind)
228 -- You might think that (->) should have type (?? -> ? -> *), and you'd be right
229 -- But if we do that we get kind errors when saying
230 -- instance Control.Arrow (->)
231 -- becuase the expected kind is (*->*->*). The trouble is that the
232 -- expected/actual stuff in the unifier does not go contra-variant, whereas
233 -- the kind sub-typing does. Sigh. It really only matters if you use (->) in
234 -- a prefix way, thus: (->) Int# Int#. And this is unusual.
235 -- because they are never in scope in the source
239 %************************************************************************
243 %************************************************************************
246 -- | See "Type#kind_subtyping" for details of the distinction between the 'Kind' 'TyCon's
247 tySuperKindTyCon, liftedTypeKindTyCon,
248 openTypeKindTyCon, unliftedTypeKindTyCon,
249 ubxTupleKindTyCon, argTypeKindTyCon
251 tySuperKindTyConName, liftedTypeKindTyConName,
252 openTypeKindTyConName, unliftedTypeKindTyConName,
253 ubxTupleKindTyConName, argTypeKindTyConName
256 tySuperKindTyCon = mkSuperKindTyCon tySuperKindTyConName
257 liftedTypeKindTyCon = mkKindTyCon liftedTypeKindTyConName tySuperKind
258 openTypeKindTyCon = mkKindTyCon openTypeKindTyConName tySuperKind
259 unliftedTypeKindTyCon = mkKindTyCon unliftedTypeKindTyConName tySuperKind
260 ubxTupleKindTyCon = mkKindTyCon ubxTupleKindTyConName tySuperKind
261 argTypeKindTyCon = mkKindTyCon argTypeKindTyConName tySuperKind
263 --------------------------
264 -- ... and now their names
266 tySuperKindTyConName = mkPrimTyConName (fsLit "BOX") tySuperKindTyConKey tySuperKindTyCon
267 liftedTypeKindTyConName = mkPrimTyConName (fsLit "*") liftedTypeKindTyConKey liftedTypeKindTyCon
268 openTypeKindTyConName = mkPrimTyConName (fsLit "?") openTypeKindTyConKey openTypeKindTyCon
269 unliftedTypeKindTyConName = mkPrimTyConName (fsLit "#") unliftedTypeKindTyConKey unliftedTypeKindTyCon
270 ubxTupleKindTyConName = mkPrimTyConName (fsLit "(#)") ubxTupleKindTyConKey ubxTupleKindTyCon
271 argTypeKindTyConName = mkPrimTyConName (fsLit "??") argTypeKindTyConKey argTypeKindTyCon
273 mkPrimTyConName :: FastString -> Unique -> TyCon -> Name
274 mkPrimTyConName occ key tycon = mkWiredInName gHC_PRIM (mkTcOccFS occ)
278 -- All of the super kinds and kinds are defined in Prim and use BuiltInSyntax,
279 -- because they are never in scope in the source
284 kindTyConType :: TyCon -> Type
285 kindTyConType kind = TyConApp kind []
287 -- | See "Type#kind_subtyping" for details of the distinction between these 'Kind's
288 liftedTypeKind, unliftedTypeKind, openTypeKind, argTypeKind, ubxTupleKind :: Kind
290 liftedTypeKind = kindTyConType liftedTypeKindTyCon
291 unliftedTypeKind = kindTyConType unliftedTypeKindTyCon
292 openTypeKind = kindTyConType openTypeKindTyCon
293 argTypeKind = kindTyConType argTypeKindTyCon
294 ubxTupleKind = kindTyConType ubxTupleKindTyCon
296 -- | Given two kinds @k1@ and @k2@, creates the 'Kind' @k1 -> k2@
297 mkArrowKind :: Kind -> Kind -> Kind
298 mkArrowKind k1 k2 = FunTy k1 k2
300 -- | Iterated application of 'mkArrowKind'
301 mkArrowKinds :: [Kind] -> Kind -> Kind
302 mkArrowKinds arg_kinds result_kind = foldr mkArrowKind result_kind arg_kinds
304 tySuperKind :: SuperKind
305 tySuperKind = kindTyConType tySuperKindTyCon
308 %************************************************************************
310 \subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
312 %************************************************************************
316 pcPrimTyCon :: Name -> Int -> PrimRep -> TyCon
317 pcPrimTyCon name arity rep
318 = mkPrimTyCon name kind arity rep
320 kind = mkArrowKinds (replicate arity liftedTypeKind) result_kind
321 result_kind = unliftedTypeKind
323 pcPrimTyCon0 :: Name -> PrimRep -> TyCon
324 pcPrimTyCon0 name rep
325 = mkPrimTyCon name result_kind 0 rep
327 result_kind = unliftedTypeKind
330 charPrimTy = mkTyConTy charPrimTyCon
331 charPrimTyCon :: TyCon
332 charPrimTyCon = pcPrimTyCon0 charPrimTyConName WordRep
335 intPrimTy = mkTyConTy intPrimTyCon
336 intPrimTyCon :: TyCon
337 intPrimTyCon = pcPrimTyCon0 intPrimTyConName IntRep
340 int32PrimTy = mkTyConTy int32PrimTyCon
341 int32PrimTyCon :: TyCon
342 int32PrimTyCon = pcPrimTyCon0 int32PrimTyConName IntRep
345 int64PrimTy = mkTyConTy int64PrimTyCon
346 int64PrimTyCon :: TyCon
347 int64PrimTyCon = pcPrimTyCon0 int64PrimTyConName Int64Rep
350 wordPrimTy = mkTyConTy wordPrimTyCon
351 wordPrimTyCon :: TyCon
352 wordPrimTyCon = pcPrimTyCon0 wordPrimTyConName WordRep
355 word32PrimTy = mkTyConTy word32PrimTyCon
356 word32PrimTyCon :: TyCon
357 word32PrimTyCon = pcPrimTyCon0 word32PrimTyConName WordRep
360 word64PrimTy = mkTyConTy word64PrimTyCon
361 word64PrimTyCon :: TyCon
362 word64PrimTyCon = pcPrimTyCon0 word64PrimTyConName Word64Rep
365 addrPrimTy = mkTyConTy addrPrimTyCon
366 addrPrimTyCon :: TyCon
367 addrPrimTyCon = pcPrimTyCon0 addrPrimTyConName AddrRep
370 floatPrimTy = mkTyConTy floatPrimTyCon
371 floatPrimTyCon :: TyCon
372 floatPrimTyCon = pcPrimTyCon0 floatPrimTyConName FloatRep
375 doublePrimTy = mkTyConTy doublePrimTyCon
376 doublePrimTyCon :: TyCon
377 doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName DoubleRep
381 %************************************************************************
383 \subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
385 %************************************************************************
389 There is a perfectly ordinary type constructor (~) that represents the type
390 of coercions (which, remember, are values). For example
391 Refl Int :: Int ~ Int
393 Atcually it is not quite "perfectly ordinary" because it is kind-polymorphic:
394 Refl Maybe :: Maybe ~ Maybe
396 So the true kind of (~) :: forall k. k -> k -> #. But we don't have
397 polymorphic kinds (yet). However, (~) really only appears saturated in
398 which case there is no problem in finding the kind of (ty1 ~ ty2). So
399 we check that in CoreLint (and, in an assertion, in Kind.typeKind).
401 Note [The State# TyCon]
402 ~~~~~~~~~~~~~~~~~~~~~~~
403 State# is the primitive, unlifted type of states. It has one type parameter,
409 where s is a type variable. The only purpose of the type parameter is to
410 keep different state threads separate. It is represented by nothing at all.
413 mkStatePrimTy :: Type -> Type
414 mkStatePrimTy ty = mkTyConApp statePrimTyCon [ty]
416 statePrimTyCon :: TyCon -- See Note [The State# TyCon]
417 statePrimTyCon = pcPrimTyCon statePrimTyConName 1 VoidRep
419 eqPredPrimTyCon :: TyCon -- The representation type for equality predicates
420 -- See Note [The (~) TyCon]
421 eqPredPrimTyCon = pcPrimTyCon eqPredPrimTyConName 2 VoidRep
424 RealWorld is deeply magical. It is *primitive*, but it is not
425 *unlifted* (hence ptrArg). We never manipulate values of type
426 RealWorld; it's only used in the type system, to parameterise State#.
429 realWorldTyCon :: TyCon
430 realWorldTyCon = mkLiftedPrimTyCon realWorldTyConName liftedTypeKind 0 PtrRep
432 realWorldTy = mkTyConTy realWorldTyCon
433 realWorldStatePrimTy :: Type
434 realWorldStatePrimTy = mkStatePrimTy realWorldTy -- State# RealWorld
437 Note: the ``state-pairing'' types are not truly primitive, so they are
438 defined in \tr{TysWiredIn.lhs}, not here.
440 %************************************************************************
442 \subsection[TysPrim-arrays]{The primitive array types}
444 %************************************************************************
447 arrayPrimTyCon, mutableArrayPrimTyCon, mutableByteArrayPrimTyCon,
448 byteArrayPrimTyCon :: TyCon
449 arrayPrimTyCon = pcPrimTyCon arrayPrimTyConName 1 PtrRep
450 mutableArrayPrimTyCon = pcPrimTyCon mutableArrayPrimTyConName 2 PtrRep
451 mutableByteArrayPrimTyCon = pcPrimTyCon mutableByteArrayPrimTyConName 1 PtrRep
452 byteArrayPrimTyCon = pcPrimTyCon0 byteArrayPrimTyConName PtrRep
454 mkArrayPrimTy :: Type -> Type
455 mkArrayPrimTy elt = mkTyConApp arrayPrimTyCon [elt]
456 byteArrayPrimTy :: Type
457 byteArrayPrimTy = mkTyConTy byteArrayPrimTyCon
458 mkMutableArrayPrimTy :: Type -> Type -> Type
459 mkMutableArrayPrimTy s elt = mkTyConApp mutableArrayPrimTyCon [s, elt]
460 mkMutableByteArrayPrimTy :: Type -> Type
461 mkMutableByteArrayPrimTy s = mkTyConApp mutableByteArrayPrimTyCon [s]
464 %************************************************************************
466 \subsection[TysPrim-mut-var]{The mutable variable type}
468 %************************************************************************
471 mutVarPrimTyCon :: TyCon
472 mutVarPrimTyCon = pcPrimTyCon mutVarPrimTyConName 2 PtrRep
474 mkMutVarPrimTy :: Type -> Type -> Type
475 mkMutVarPrimTy s elt = mkTyConApp mutVarPrimTyCon [s, elt]
478 %************************************************************************
480 \subsection[TysPrim-synch-var]{The synchronizing variable type}
482 %************************************************************************
485 mVarPrimTyCon :: TyCon
486 mVarPrimTyCon = pcPrimTyCon mVarPrimTyConName 2 PtrRep
488 mkMVarPrimTy :: Type -> Type -> Type
489 mkMVarPrimTy s elt = mkTyConApp mVarPrimTyCon [s, elt]
492 %************************************************************************
494 \subsection[TysPrim-stm-var]{The transactional variable type}
496 %************************************************************************
499 tVarPrimTyCon :: TyCon
500 tVarPrimTyCon = pcPrimTyCon tVarPrimTyConName 2 PtrRep
502 mkTVarPrimTy :: Type -> Type -> Type
503 mkTVarPrimTy s elt = mkTyConApp tVarPrimTyCon [s, elt]
506 %************************************************************************
508 \subsection[TysPrim-stable-ptrs]{The stable-pointer type}
510 %************************************************************************
513 stablePtrPrimTyCon :: TyCon
514 stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConName 1 AddrRep
516 mkStablePtrPrimTy :: Type -> Type
517 mkStablePtrPrimTy ty = mkTyConApp stablePtrPrimTyCon [ty]
520 %************************************************************************
522 \subsection[TysPrim-stable-names]{The stable-name type}
524 %************************************************************************
527 stableNamePrimTyCon :: TyCon
528 stableNamePrimTyCon = pcPrimTyCon stableNamePrimTyConName 1 PtrRep
530 mkStableNamePrimTy :: Type -> Type
531 mkStableNamePrimTy ty = mkTyConApp stableNamePrimTyCon [ty]
534 %************************************************************************
536 \subsection[TysPrim-BCOs]{The ``bytecode object'' type}
538 %************************************************************************
542 bcoPrimTy = mkTyConTy bcoPrimTyCon
543 bcoPrimTyCon :: TyCon
544 bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName PtrRep
547 %************************************************************************
549 \subsection[TysPrim-Weak]{The ``weak pointer'' type}
551 %************************************************************************
554 weakPrimTyCon :: TyCon
555 weakPrimTyCon = pcPrimTyCon weakPrimTyConName 1 PtrRep
557 mkWeakPrimTy :: Type -> Type
558 mkWeakPrimTy v = mkTyConApp weakPrimTyCon [v]
561 %************************************************************************
563 \subsection[TysPrim-thread-ids]{The ``thread id'' type}
565 %************************************************************************
567 A thread id is represented by a pointer to the TSO itself, to ensure
568 that they are always unique and we can always find the TSO for a given
569 thread id. However, this has the unfortunate consequence that a
570 ThreadId# for a given thread is treated as a root by the garbage
571 collector and can keep TSOs around for too long.
573 Hence the programmer API for thread manipulation uses a weak pointer
574 to the thread id internally.
577 threadIdPrimTy :: Type
578 threadIdPrimTy = mkTyConTy threadIdPrimTyCon
579 threadIdPrimTyCon :: TyCon
580 threadIdPrimTyCon = pcPrimTyCon0 threadIdPrimTyConName PtrRep
585 %************************************************************************
589 %************************************************************************
593 The type constructor Any::* has these properties
595 * It is defined in module GHC.Prim, and exported so that it is
596 available to users. For this reason it's treated like any other
598 - has a fixed unique, anyTyConKey,
599 - lives in the global name cache
600 - built with TyCon.PrimTyCon
602 * It is lifted, and hence represented by a pointer
604 * It is inhabited by at least one value, namely bottom
606 * You can unsafely coerce any lifted type to Ayny, and back.
608 * It does not claim to be a *data* type, and that's important for
609 the code generator, because the code gen may *enter* a data value
610 but never enters a function value.
612 * It is used to instantiate otherwise un-constrained type variables of kind *
613 For example length Any []
614 See Note [Strangely-kinded void TyCons]
616 In addition, we have a potentially-infinite family of types, one for
617 each kind /other than/ *, needed to instantiate otherwise
618 un-constrained type variables of kinds other than *. This is a bit
619 like tuples; there is a potentially-infinite family. They have slightly
620 different characteristics to Any::*:
622 * They are built with TyCon.AnyTyCon
623 * They have non-user-writable names like "Any(*->*)"
624 * They are not exported by GHC.Prim
625 * They are uninhabited (of course; not kind *)
626 * They have a unique derived from their OccName (see Note [Uniques of Any])
627 * Their Names do not live in the global name cache
629 Note [Uniques of Any]
630 ~~~~~~~~~~~~~~~~~~~~~
631 Although Any(*->*), say, doesn't have a binding site, it still needs
632 to have a Unique. Unlike tuples (which are also an infinite family)
633 there is no convenient way to index them, so we use the Unique from
634 their OccName instead. That should be unique,
635 - both wrt each other, because their strings differ
637 - and wrt any other Name, because Names get uniques with
638 various 'char' tags, but the OccName of Any will
639 get a Unique built with mkTcOccUnique, which has a particular 'char'
640 tag; see Unique.mkTcOccUnique!
642 Note [Strangely-kinded void TyCons]
643 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
644 See Trac #959 for more examples
646 When the type checker finds a type variable with no binding, which
647 means it can be instantiated with an arbitrary type, it usually
648 instantiates it to Void. Eg.
654 But in really obscure programs, the type variable might have a kind
655 other than *, so we need to invent a suitably-kinded type.
659 Any(*->*) for kind *->*
664 anyTyConName = mkPrimTc (fsLit "Any") anyTyConKey anyTyCon
667 anyTyCon = mkLiftedPrimTyCon anyTyConName liftedTypeKind 0 PtrRep
669 anyTypeOfKind :: Kind -> Type
670 anyTypeOfKind kind = mkTyConApp (anyTyConOfKind kind) []
672 anyTyConOfKind :: Kind -> TyCon
673 -- Map all superkinds of liftedTypeKind to liftedTypeKind
675 | isLiftedTypeKind kind = anyTyCon
678 -- Derive the name from the kind, thus:
679 -- Any(*->*), Any(*->*->*)
680 -- These are names that can't be written by the user,
681 -- and are not allocated in the global name cache
682 str = "Any" ++ showSDoc (pprParendKind kind)
685 uniq = getUnique occ -- See Note [Uniques of Any]
686 name = mkWiredInName gHC_PRIM occ uniq (ATyCon tycon) UserSyntax
687 tycon = mkAnyTyCon name kind