1{-
2(c) The AQUA Project, Glasgow University, 1994-1998
3
4
5\section[TysPrim]{Wired-in knowledge about primitive types}
6-}
7
8{-# LANGUAGE CPP #-}
9
10-- | This module defines TyCons that can't be expressed in Haskell.
11--   They are all, therefore, wired-in TyCons.  C.f module TysWiredIn
12module TysPrim(
13        mkPrimTyConName, -- For implicit parameters in TysWiredIn only
14
15        mkTemplateKindVars, mkTemplateTyVars, mkTemplateTyVarsFrom,
16        mkTemplateKiTyVars, mkTemplateKiTyVar,
17
18        mkTemplateTyConBinders, mkTemplateKindTyConBinders,
19        mkTemplateAnonTyConBinders,
20
21        alphaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar,
22        alphaTys, alphaTy, betaTy, gammaTy, deltaTy,
23        alphaTyVarsUnliftedRep, alphaTyVarUnliftedRep,
24        alphaTysUnliftedRep, alphaTyUnliftedRep,
25        runtimeRep1TyVar, runtimeRep2TyVar, runtimeRep1Ty, runtimeRep2Ty,
26        openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar,
27
28        -- Kind constructors...
29        tYPETyCon, tYPETyConName,
30
31        -- Kinds
32        tYPE, primRepToRuntimeRep,
33
34        funTyCon, funTyConName,
35        unexposedPrimTyCons, exposedPrimTyCons, primTyCons,
36
37        charPrimTyCon,          charPrimTy, charPrimTyConName,
38        intPrimTyCon,           intPrimTy, intPrimTyConName,
39        wordPrimTyCon,          wordPrimTy, wordPrimTyConName,
40        addrPrimTyCon,          addrPrimTy, addrPrimTyConName,
41        floatPrimTyCon,         floatPrimTy, floatPrimTyConName,
42        doublePrimTyCon,        doublePrimTy, doublePrimTyConName,
43
44        voidPrimTyCon,          voidPrimTy,
45        statePrimTyCon,         mkStatePrimTy,
46        realWorldTyCon,         realWorldTy, realWorldStatePrimTy,
47
48        proxyPrimTyCon,         mkProxyPrimTy,
49
50        arrayPrimTyCon, mkArrayPrimTy,
51        byteArrayPrimTyCon,     byteArrayPrimTy,
52        arrayArrayPrimTyCon, mkArrayArrayPrimTy,
53        smallArrayPrimTyCon, mkSmallArrayPrimTy,
54        mutableArrayPrimTyCon, mkMutableArrayPrimTy,
55        mutableByteArrayPrimTyCon, mkMutableByteArrayPrimTy,
56        mutableArrayArrayPrimTyCon, mkMutableArrayArrayPrimTy,
57        smallMutableArrayPrimTyCon, mkSmallMutableArrayPrimTy,
58        mutVarPrimTyCon, mkMutVarPrimTy,
59
60        mVarPrimTyCon,                  mkMVarPrimTy,
61        tVarPrimTyCon,                  mkTVarPrimTy,
62        stablePtrPrimTyCon,             mkStablePtrPrimTy,
63        stableNamePrimTyCon,            mkStableNamePrimTy,
64        compactPrimTyCon,               compactPrimTy,
65        bcoPrimTyCon,                   bcoPrimTy,
66        weakPrimTyCon,                  mkWeakPrimTy,
67        threadIdPrimTyCon,              threadIdPrimTy,
68
69        int8PrimTyCon,          int8PrimTy, int8PrimTyConName,
70        word8PrimTyCon,         word8PrimTy, word8PrimTyConName,
71
72        int16PrimTyCon,         int16PrimTy, int16PrimTyConName,
73        word16PrimTyCon,        word16PrimTy, word16PrimTyConName,
74
75        int32PrimTyCon,         int32PrimTy, int32PrimTyConName,
76        word32PrimTyCon,        word32PrimTy, word32PrimTyConName,
77
78        int64PrimTyCon,         int64PrimTy, int64PrimTyConName,
79        word64PrimTyCon,        word64PrimTy, word64PrimTyConName,
80
81        eqPrimTyCon,            -- ty1 ~# ty2
82        eqReprPrimTyCon,        -- ty1 ~R# ty2  (at role Representational)
83        eqPhantPrimTyCon,       -- ty1 ~P# ty2  (at role Phantom)
84        equalityTyCon,
85
86        -- * SIMD
87#include "primop-vector-tys-exports.hs-incl"
88  ) where
89
90#include "HsVersions.h"
91
92import GhcPrelude
93
94import {-# SOURCE #-} TysWiredIn
95  ( runtimeRepTy, unboxedTupleKind, liftedTypeKind
96  , vecRepDataConTyCon, tupleRepDataConTyCon
97  , liftedRepDataConTy, unliftedRepDataConTy
98  , intRepDataConTy
99  , int8RepDataConTy, int16RepDataConTy, int32RepDataConTy, int64RepDataConTy
100  , wordRepDataConTy
101  , word16RepDataConTy, word8RepDataConTy, word32RepDataConTy, word64RepDataConTy
102  , addrRepDataConTy
103  , floatRepDataConTy, doubleRepDataConTy
104  , vec2DataConTy, vec4DataConTy, vec8DataConTy, vec16DataConTy, vec32DataConTy
105  , vec64DataConTy
106  , int8ElemRepDataConTy, int16ElemRepDataConTy, int32ElemRepDataConTy
107  , int64ElemRepDataConTy, word8ElemRepDataConTy, word16ElemRepDataConTy
108  , word32ElemRepDataConTy, word64ElemRepDataConTy, floatElemRepDataConTy
109  , doubleElemRepDataConTy
110  , mkPromotedListTy )
111
112import Var              ( TyVar, mkTyVar )
113import Name
114import TyCon
115import SrcLoc
116import Unique
117import PrelNames
118import FastString
119import Outputable
120import TyCoRep   -- Doesn't need special access, but this is easier to avoid
121                 -- import loops which show up if you import Type instead
122
123import Data.Char
124
125{-
126************************************************************************
127*                                                                      *
128\subsection{Primitive type constructors}
129*                                                                      *
130************************************************************************
131-}
132
133primTyCons :: [TyCon]
134primTyCons = unexposedPrimTyCons ++ exposedPrimTyCons
135
136-- | Primitive 'TyCon's that are defined in "GHC.Prim" but not exposed.
137-- It's important to keep these separate as we don't want users to be able to
138-- write them (see #15209) or see them in GHCi's @:browse@ output
139-- (see #12023).
140unexposedPrimTyCons :: [TyCon]
141unexposedPrimTyCons
142  = [ eqPrimTyCon
143    , eqReprPrimTyCon
144    , eqPhantPrimTyCon
145    ]
146
147-- | Primitive 'TyCon's that are defined in, and exported from, "GHC.Prim".
148exposedPrimTyCons :: [TyCon]
149exposedPrimTyCons
150  = [ addrPrimTyCon
151    , arrayPrimTyCon
152    , byteArrayPrimTyCon
153    , arrayArrayPrimTyCon
154    , smallArrayPrimTyCon
155    , charPrimTyCon
156    , doublePrimTyCon
157    , floatPrimTyCon
158    , intPrimTyCon
159    , int8PrimTyCon
160    , int16PrimTyCon
161    , int32PrimTyCon
162    , int64PrimTyCon
163    , bcoPrimTyCon
164    , weakPrimTyCon
165    , mutableArrayPrimTyCon
166    , mutableByteArrayPrimTyCon
167    , mutableArrayArrayPrimTyCon
168    , smallMutableArrayPrimTyCon
169    , mVarPrimTyCon
170    , tVarPrimTyCon
171    , mutVarPrimTyCon
172    , realWorldTyCon
173    , stablePtrPrimTyCon
174    , stableNamePrimTyCon
175    , compactPrimTyCon
176    , statePrimTyCon
177    , voidPrimTyCon
178    , proxyPrimTyCon
179    , threadIdPrimTyCon
180    , wordPrimTyCon
181    , word8PrimTyCon
182    , word16PrimTyCon
183    , word32PrimTyCon
184    , word64PrimTyCon
185
186    , tYPETyCon
187
188#include "primop-vector-tycons.hs-incl"
189    ]
190
191mkPrimTc :: FastString -> Unique -> TyCon -> Name
192mkPrimTc fs unique tycon
193  = mkWiredInName gHC_PRIM (mkTcOccFS fs)
194                  unique
195                  (ATyCon tycon)        -- Relevant TyCon
196                  UserSyntax
197
198mkBuiltInPrimTc :: FastString -> Unique -> TyCon -> Name
199mkBuiltInPrimTc fs unique tycon
200  = mkWiredInName gHC_PRIM (mkTcOccFS fs)
201                  unique
202                  (ATyCon tycon)        -- Relevant TyCon
203                  BuiltInSyntax
204
205
206charPrimTyConName, intPrimTyConName, int8PrimTyConName, int16PrimTyConName, int32PrimTyConName, int64PrimTyConName, wordPrimTyConName, word32PrimTyConName, word8PrimTyConName, word16PrimTyConName, word64PrimTyConName, addrPrimTyConName, floatPrimTyConName, doublePrimTyConName, statePrimTyConName, proxyPrimTyConName, realWorldTyConName, arrayPrimTyConName, arrayArrayPrimTyConName, smallArrayPrimTyConName, byteArrayPrimTyConName, mutableArrayPrimTyConName, mutableByteArrayPrimTyConName, mutableArrayArrayPrimTyConName, smallMutableArrayPrimTyConName, mutVarPrimTyConName, mVarPrimTyConName, tVarPrimTyConName, stablePtrPrimTyConName, stableNamePrimTyConName, compactPrimTyConName, bcoPrimTyConName, weakPrimTyConName, threadIdPrimTyConName, eqPrimTyConName, eqReprPrimTyConName, eqPhantPrimTyConName, voidPrimTyConName :: Name
207charPrimTyConName             = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon
208intPrimTyConName              = mkPrimTc (fsLit "Int#") intPrimTyConKey  intPrimTyCon
209int8PrimTyConName             = mkPrimTc (fsLit "Int8#") int8PrimTyConKey int8PrimTyCon
210int16PrimTyConName            = mkPrimTc (fsLit "Int16#") int16PrimTyConKey int16PrimTyCon
211int32PrimTyConName            = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon
212int64PrimTyConName            = mkPrimTc (fsLit "Int64#") int64PrimTyConKey int64PrimTyCon
213wordPrimTyConName             = mkPrimTc (fsLit "Word#") wordPrimTyConKey wordPrimTyCon
214word8PrimTyConName            = mkPrimTc (fsLit "Word8#") word8PrimTyConKey word8PrimTyCon
215word16PrimTyConName           = mkPrimTc (fsLit "Word16#") word16PrimTyConKey word16PrimTyCon
216word32PrimTyConName           = mkPrimTc (fsLit "Word32#") word32PrimTyConKey word32PrimTyCon
217word64PrimTyConName           = mkPrimTc (fsLit "Word64#") word64PrimTyConKey word64PrimTyCon
218addrPrimTyConName             = mkPrimTc (fsLit "Addr#") addrPrimTyConKey addrPrimTyCon
219floatPrimTyConName            = mkPrimTc (fsLit "Float#") floatPrimTyConKey floatPrimTyCon
220doublePrimTyConName           = mkPrimTc (fsLit "Double#") doublePrimTyConKey doublePrimTyCon
221statePrimTyConName            = mkPrimTc (fsLit "State#") statePrimTyConKey statePrimTyCon
222voidPrimTyConName             = mkPrimTc (fsLit "Void#") voidPrimTyConKey voidPrimTyCon
223proxyPrimTyConName            = mkPrimTc (fsLit "Proxy#") proxyPrimTyConKey proxyPrimTyCon
224eqPrimTyConName               = mkPrimTc (fsLit "~#") eqPrimTyConKey eqPrimTyCon
225eqReprPrimTyConName           = mkBuiltInPrimTc (fsLit "~R#") eqReprPrimTyConKey eqReprPrimTyCon
226eqPhantPrimTyConName          = mkBuiltInPrimTc (fsLit "~P#") eqPhantPrimTyConKey eqPhantPrimTyCon
227realWorldTyConName            = mkPrimTc (fsLit "RealWorld") realWorldTyConKey realWorldTyCon
228arrayPrimTyConName            = mkPrimTc (fsLit "Array#") arrayPrimTyConKey arrayPrimTyCon
229byteArrayPrimTyConName        = mkPrimTc (fsLit "ByteArray#") byteArrayPrimTyConKey byteArrayPrimTyCon
230arrayArrayPrimTyConName           = mkPrimTc (fsLit "ArrayArray#") arrayArrayPrimTyConKey arrayArrayPrimTyCon
231smallArrayPrimTyConName       = mkPrimTc (fsLit "SmallArray#") smallArrayPrimTyConKey smallArrayPrimTyCon
232mutableArrayPrimTyConName     = mkPrimTc (fsLit "MutableArray#") mutableArrayPrimTyConKey mutableArrayPrimTyCon
233mutableByteArrayPrimTyConName = mkPrimTc (fsLit "MutableByteArray#") mutableByteArrayPrimTyConKey mutableByteArrayPrimTyCon
234mutableArrayArrayPrimTyConName= mkPrimTc (fsLit "MutableArrayArray#") mutableArrayArrayPrimTyConKey mutableArrayArrayPrimTyCon
235smallMutableArrayPrimTyConName= mkPrimTc (fsLit "SmallMutableArray#") smallMutableArrayPrimTyConKey smallMutableArrayPrimTyCon
236mutVarPrimTyConName           = mkPrimTc (fsLit "MutVar#") mutVarPrimTyConKey mutVarPrimTyCon
237mVarPrimTyConName             = mkPrimTc (fsLit "MVar#") mVarPrimTyConKey mVarPrimTyCon
238tVarPrimTyConName             = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPrimTyCon
239stablePtrPrimTyConName        = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon
240stableNamePrimTyConName       = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon
241compactPrimTyConName          = mkPrimTc (fsLit "Compact#") compactPrimTyConKey compactPrimTyCon
242bcoPrimTyConName              = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon
243weakPrimTyConName             = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon
244threadIdPrimTyConName         = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon
245
246{-
247************************************************************************
248*                                                                      *
249\subsection{Support code}
250*                                                                      *
251************************************************************************
252
253alphaTyVars is a list of type variables for use in templates:
254        ["a", "b", ..., "z", "t1", "t2", ... ]
255-}
256
257mkTemplateKindVar :: Kind -> TyVar
258mkTemplateKindVar = mkTyVar (mk_tv_name 0 "k")
259
260mkTemplateKindVars :: [Kind] -> [TyVar]
261-- k0  with unique (mkAlphaTyVarUnique 0)
262-- k1  with unique (mkAlphaTyVarUnique 1)
263-- ... etc
264mkTemplateKindVars [kind] = [mkTemplateKindVar kind]
265  -- Special case for one kind: just "k"
266mkTemplateKindVars kinds
267  = [ mkTyVar (mk_tv_name u ('k' : show u)) kind
268    | (kind, u) <- kinds `zip` [0..] ]
269mk_tv_name :: Int -> String -> Name
270mk_tv_name u s = mkInternalName (mkAlphaTyVarUnique u)
271                                (mkTyVarOccFS (mkFastString s))
272                                noSrcSpan
273
274mkTemplateTyVarsFrom :: Int -> [Kind] -> [TyVar]
275-- a  with unique (mkAlphaTyVarUnique n)
276-- b  with unique (mkAlphaTyVarUnique n+1)
277-- ... etc
278-- Typically called as
279--   mkTemplateTyVarsFrom (length kv_bndrs) kinds
280-- where kv_bndrs are the kind-level binders of a TyCon
281mkTemplateTyVarsFrom n kinds
282  = [ mkTyVar name kind
283    | (kind, index) <- zip kinds [0..],
284      let ch_ord = index + ord 'a'
285          name_str | ch_ord <= ord 'z' = [chr ch_ord]
286                   | otherwise         = 't':show index
287          name = mk_tv_name (index + n) name_str
288    ]
289
290mkTemplateTyVars :: [Kind] -> [TyVar]
291mkTemplateTyVars = mkTemplateTyVarsFrom 1
292
293mkTemplateTyConBinders
294    :: [Kind]                -- [k1, .., kn]   Kinds of kind-forall'd vars
295    -> ([Kind] -> [Kind])    -- Arg is [kv1:k1, ..., kvn:kn]
296                             --     same length as first arg
297                             -- Result is anon arg kinds
298    -> [TyConBinder]
299mkTemplateTyConBinders kind_var_kinds mk_anon_arg_kinds
300  = kv_bndrs ++ tv_bndrs
301  where
302    kv_bndrs   = mkTemplateKindTyConBinders kind_var_kinds
303    anon_kinds = mk_anon_arg_kinds (mkTyVarTys (binderVars kv_bndrs))
304    tv_bndrs   = mkTemplateAnonTyConBindersFrom (length kv_bndrs) anon_kinds
305
306mkTemplateKiTyVars
307    :: [Kind]                -- [k1, .., kn]   Kinds of kind-forall'd vars
308    -> ([Kind] -> [Kind])    -- Arg is [kv1:k1, ..., kvn:kn]
309                             --     same length as first arg
310                             -- Result is anon arg kinds [ak1, .., akm]
311    -> [TyVar]   -- [kv1:k1, ..., kvn:kn, av1:ak1, ..., avm:akm]
312-- Example: if you want the tyvars for
313--   forall (r:RuntimeRep) (a:TYPE r) (b:*). blah
314-- call mkTemplateKiTyVars [RuntimeRep] (\[r] -> [TYPE r, *])
315mkTemplateKiTyVars kind_var_kinds mk_arg_kinds
316  = kv_bndrs ++ tv_bndrs
317  where
318    kv_bndrs   = mkTemplateKindVars kind_var_kinds
319    anon_kinds = mk_arg_kinds (mkTyVarTys kv_bndrs)
320    tv_bndrs   = mkTemplateTyVarsFrom (length kv_bndrs) anon_kinds
321
322mkTemplateKiTyVar
323    :: Kind                  -- [k1, .., kn]   Kind of kind-forall'd var
324    -> (Kind -> [Kind])      -- Arg is kv1:k1
325                             -- Result is anon arg kinds [ak1, .., akm]
326    -> [TyVar]   -- [kv1:k1, ..., kvn:kn, av1:ak1, ..., avm:akm]
327-- Example: if you want the tyvars for
328--   forall (r:RuntimeRep) (a:TYPE r) (b:*). blah
329-- call mkTemplateKiTyVar RuntimeRep (\r -> [TYPE r, *])
330mkTemplateKiTyVar kind mk_arg_kinds
331  = kv_bndr : tv_bndrs
332  where
333    kv_bndr    = mkTemplateKindVar kind
334    anon_kinds = mk_arg_kinds (mkTyVarTy kv_bndr)
335    tv_bndrs   = mkTemplateTyVarsFrom 1 anon_kinds
336
337mkTemplateKindTyConBinders :: [Kind] -> [TyConBinder]
338-- Makes named, Specified binders
339mkTemplateKindTyConBinders kinds = [mkNamedTyConBinder Specified tv | tv <- mkTemplateKindVars kinds]
340
341mkTemplateAnonTyConBinders :: [Kind] -> [TyConBinder]
342mkTemplateAnonTyConBinders kinds = mkAnonTyConBinders VisArg (mkTemplateTyVars kinds)
343
344mkTemplateAnonTyConBindersFrom :: Int -> [Kind] -> [TyConBinder]
345mkTemplateAnonTyConBindersFrom n kinds = mkAnonTyConBinders VisArg (mkTemplateTyVarsFrom n kinds)
346
347alphaTyVars :: [TyVar]
348alphaTyVars = mkTemplateTyVars $ repeat liftedTypeKind
349
350alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar
351(alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars
352
353alphaTys :: [Type]
354alphaTys = mkTyVarTys alphaTyVars
355alphaTy, betaTy, gammaTy, deltaTy :: Type
356(alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys
357
358alphaTyVarsUnliftedRep :: [TyVar]
359alphaTyVarsUnliftedRep = mkTemplateTyVars $ repeat (tYPE unliftedRepDataConTy)
360
361alphaTyVarUnliftedRep :: TyVar
362(alphaTyVarUnliftedRep:_) = alphaTyVarsUnliftedRep
363
364alphaTysUnliftedRep :: [Type]
365alphaTysUnliftedRep = mkTyVarTys alphaTyVarsUnliftedRep
366alphaTyUnliftedRep :: Type
367(alphaTyUnliftedRep:_) = alphaTysUnliftedRep
368
369runtimeRep1TyVar, runtimeRep2TyVar :: TyVar
370(runtimeRep1TyVar : runtimeRep2TyVar : _)
371  = drop 16 (mkTemplateTyVars (repeat runtimeRepTy))  -- selects 'q','r'
372
373runtimeRep1Ty, runtimeRep2Ty :: Type
374runtimeRep1Ty = mkTyVarTy runtimeRep1TyVar
375runtimeRep2Ty = mkTyVarTy runtimeRep2TyVar
376
377openAlphaTyVar, openBetaTyVar :: TyVar
378[openAlphaTyVar,openBetaTyVar]
379  = mkTemplateTyVars [tYPE runtimeRep1Ty, tYPE runtimeRep2Ty]
380
381openAlphaTy, openBetaTy :: Type
382openAlphaTy = mkTyVarTy openAlphaTyVar
383openBetaTy  = mkTyVarTy openBetaTyVar
384
385{-
386************************************************************************
387*                                                                      *
388                FunTyCon
389*                                                                      *
390************************************************************************
391-}
392
393funTyConName :: Name
394funTyConName = mkPrimTyConName (fsLit "->") funTyConKey funTyCon
395
396-- | The @(->)@ type constructor.
397--
398-- @
399-- (->) :: forall (rep1 :: RuntimeRep) (rep2 :: RuntimeRep).
400--         TYPE rep1 -> TYPE rep2 -> *
401-- @
402funTyCon :: TyCon
403funTyCon = mkFunTyCon funTyConName tc_bndrs tc_rep_nm
404  where
405    tc_bndrs = [ mkNamedTyConBinder Inferred runtimeRep1TyVar
406               , mkNamedTyConBinder Inferred runtimeRep2TyVar ]
407               ++ mkTemplateAnonTyConBinders [ tYPE runtimeRep1Ty
408                                             , tYPE runtimeRep2Ty
409                                             ]
410    tc_rep_nm = mkPrelTyConRepName funTyConName
411
412{-
413************************************************************************
414*                                                                      *
415                Kinds
416*                                                                      *
417************************************************************************
418
419Note [TYPE and RuntimeRep]
420~~~~~~~~~~~~~~~~~~~~~~~~~~
421All types that classify values have a kind of the form (TYPE rr), where
422
423    data RuntimeRep     -- Defined in ghc-prim:GHC.Types
424      = LiftedRep
425      | UnliftedRep
426      | IntRep
427      | FloatRep
428      .. etc ..
429
430    rr :: RuntimeRep
431
432    TYPE :: RuntimeRep -> TYPE 'LiftedRep  -- Built in
433
434So for example:
435    Int        :: TYPE 'LiftedRep
436    Array# Int :: TYPE 'UnliftedRep
437    Int#       :: TYPE 'IntRep
438    Float#     :: TYPE 'FloatRep
439    Maybe      :: TYPE 'LiftedRep -> TYPE 'LiftedRep
440    (# , #)    :: TYPE r1 -> TYPE r2 -> TYPE (TupleRep [r1, r2])
441
442We abbreviate '*' specially:
443    type * = TYPE 'LiftedRep
444
445The 'rr' parameter tells us how the value is represented at runime.
446
447Generally speaking, you can't be polymorphic in 'rr'.  E.g
448   f :: forall (rr:RuntimeRep) (a:TYPE rr). a -> [a]
449   f = /\(rr:RuntimeRep) (a:rr) \(a:rr). ...
450This is no good: we could not generate code code for 'f', because the
451calling convention for 'f' varies depending on whether the argument is
452a a Int, Int#, or Float#.  (You could imagine generating specialised
453code, one for each instantiation of 'rr', but we don't do that.)
454
455Certain functions CAN be runtime-rep-polymorphic, because the code
456generator never has to manipulate a value of type 'a :: TYPE rr'.
457
458* error :: forall (rr:RuntimeRep) (a:TYPE rr). String -> a
459  Code generator never has to manipulate the return value.
460
461* unsafeCoerce#, defined in MkId.unsafeCoerceId:
462  Always inlined to be a no-op
463     unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
464                             (a :: TYPE r1) (b :: TYPE r2).
465                             a -> b
466
467* Unboxed tuples, and unboxed sums, defined in TysWiredIn
468  Always inlined, and hence specialised to the call site
469     (#,#) :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
470                     (a :: TYPE r1) (b :: TYPE r2).
471                     a -> b -> TYPE ('TupleRep '[r1, r2])
472
473Note [PrimRep and kindPrimRep]
474~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
475As part of its source code, in TyCon, GHC has
476  data PrimRep = LiftedRep | UnliftedRep | IntRep | FloatRep | ...etc...
477
478Notice that
479 * RuntimeRep is part of the syntax tree of the program being compiled
480     (defined in a library: ghc-prim:GHC.Types)
481 * PrimRep is part of GHC's source code.
482     (defined in TyCon)
483
484We need to get from one to the other; that is what kindPrimRep does.
485Suppose we have a value
486   (v :: t) where (t :: k)
487Given this kind
488    k = TyConApp "TYPE" [rep]
489GHC needs to be able to figure out how 'v' is represented at runtime.
490It expects 'rep' to be form
491    TyConApp rr_dc args
492where 'rr_dc' is a promoteed data constructor from RuntimeRep. So
493now we need to go from 'dc' to the corresponding PrimRep.  We store this
494PrimRep in the promoted data constructor itself: see TyCon.promDcRepInfo.
495
496-}
497
498tYPETyCon :: TyCon
499tYPETyConName :: Name
500
501tYPETyCon = mkKindTyCon tYPETyConName
502                        (mkTemplateAnonTyConBinders [runtimeRepTy])
503                        liftedTypeKind
504                        [Nominal]
505                        (mkPrelTyConRepName tYPETyConName)
506
507--------------------------
508-- ... and now their names
509
510-- If you edit these, you may need to update the GHC formalism
511-- See Note [GHC Formalism] in coreSyn/CoreLint.hs
512tYPETyConName             = mkPrimTyConName (fsLit "TYPE") tYPETyConKey tYPETyCon
513
514mkPrimTyConName :: FastString -> Unique -> TyCon -> Name
515mkPrimTyConName = mkPrimTcName BuiltInSyntax
516  -- All of the super kinds and kinds are defined in Prim,
517  -- and use BuiltInSyntax, because they are never in scope in the source
518
519mkPrimTcName :: BuiltInSyntax -> FastString -> Unique -> TyCon -> Name
520mkPrimTcName built_in_syntax occ key tycon
521  = mkWiredInName gHC_PRIM (mkTcOccFS occ) key (ATyCon tycon) built_in_syntax
522
523-----------------------------
524-- | Given a RuntimeRep, applies TYPE to it.
525-- see Note [TYPE and RuntimeRep]
526tYPE :: Type -> Type
527tYPE rr = TyConApp tYPETyCon [rr]
528
529{-
530************************************************************************
531*                                                                      *
532\subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
533*                                                                      *
534************************************************************************
535-}
536
537-- only used herein
538pcPrimTyCon :: Name -> [Role] -> PrimRep -> TyCon
539pcPrimTyCon name roles rep
540  = mkPrimTyCon name binders result_kind roles
541  where
542    binders     = mkTemplateAnonTyConBinders (map (const liftedTypeKind) roles)
543    result_kind = tYPE (primRepToRuntimeRep rep)
544
545-- | Convert a 'PrimRep' to a 'Type' of kind RuntimeRep
546-- Defined here to avoid (more) module loops
547primRepToRuntimeRep :: PrimRep -> Type
548primRepToRuntimeRep rep = case rep of
549  VoidRep       -> TyConApp tupleRepDataConTyCon [mkPromotedListTy runtimeRepTy []]
550  LiftedRep     -> liftedRepDataConTy
551  UnliftedRep   -> unliftedRepDataConTy
552  IntRep        -> intRepDataConTy
553  Int8Rep       -> int8RepDataConTy
554  Int16Rep      -> int16RepDataConTy
555  Int32Rep      -> int32RepDataConTy
556  Int64Rep      -> int64RepDataConTy
557  WordRep       -> wordRepDataConTy
558  Word8Rep      -> word8RepDataConTy
559  Word16Rep     -> word16RepDataConTy
560  Word32Rep     -> word32RepDataConTy
561  Word64Rep     -> word64RepDataConTy
562  AddrRep       -> addrRepDataConTy
563  FloatRep      -> floatRepDataConTy
564  DoubleRep     -> doubleRepDataConTy
565  VecRep n elem -> TyConApp vecRepDataConTyCon [n', elem']
566    where
567      n' = case n of
568        2  -> vec2DataConTy
569        4  -> vec4DataConTy
570        8  -> vec8DataConTy
571        16 -> vec16DataConTy
572        32 -> vec32DataConTy
573        64 -> vec64DataConTy
574        _  -> pprPanic "Disallowed VecCount" (ppr n)
575
576      elem' = case elem of
577        Int8ElemRep   -> int8ElemRepDataConTy
578        Int16ElemRep  -> int16ElemRepDataConTy
579        Int32ElemRep  -> int32ElemRepDataConTy
580        Int64ElemRep  -> int64ElemRepDataConTy
581        Word8ElemRep  -> word8ElemRepDataConTy
582        Word16ElemRep -> word16ElemRepDataConTy
583        Word32ElemRep -> word32ElemRepDataConTy
584        Word64ElemRep -> word64ElemRepDataConTy
585        FloatElemRep  -> floatElemRepDataConTy
586        DoubleElemRep -> doubleElemRepDataConTy
587
588pcPrimTyCon0 :: Name -> PrimRep -> TyCon
589pcPrimTyCon0 name rep
590  = pcPrimTyCon name [] rep
591
592charPrimTy :: Type
593charPrimTy      = mkTyConTy charPrimTyCon
594charPrimTyCon :: TyCon
595charPrimTyCon   = pcPrimTyCon0 charPrimTyConName WordRep
596
597intPrimTy :: Type
598intPrimTy       = mkTyConTy intPrimTyCon
599intPrimTyCon :: TyCon
600intPrimTyCon    = pcPrimTyCon0 intPrimTyConName IntRep
601
602int8PrimTy :: Type
603int8PrimTy     = mkTyConTy int8PrimTyCon
604int8PrimTyCon :: TyCon
605int8PrimTyCon  = pcPrimTyCon0 int8PrimTyConName Int8Rep
606
607int16PrimTy :: Type
608int16PrimTy    = mkTyConTy int16PrimTyCon
609int16PrimTyCon :: TyCon
610int16PrimTyCon = pcPrimTyCon0 int16PrimTyConName Int16Rep
611
612int32PrimTy :: Type
613int32PrimTy     = mkTyConTy int32PrimTyCon
614int32PrimTyCon :: TyCon
615int32PrimTyCon  = pcPrimTyCon0 int32PrimTyConName Int32Rep
616
617int64PrimTy :: Type
618int64PrimTy     = mkTyConTy int64PrimTyCon
619int64PrimTyCon :: TyCon
620int64PrimTyCon  = pcPrimTyCon0 int64PrimTyConName Int64Rep
621
622wordPrimTy :: Type
623wordPrimTy      = mkTyConTy wordPrimTyCon
624wordPrimTyCon :: TyCon
625wordPrimTyCon   = pcPrimTyCon0 wordPrimTyConName WordRep
626
627word8PrimTy :: Type
628word8PrimTy     = mkTyConTy word8PrimTyCon
629word8PrimTyCon :: TyCon
630word8PrimTyCon  = pcPrimTyCon0 word8PrimTyConName Word8Rep
631
632word16PrimTy :: Type
633word16PrimTy    = mkTyConTy word16PrimTyCon
634word16PrimTyCon :: TyCon
635word16PrimTyCon = pcPrimTyCon0 word16PrimTyConName Word16Rep
636
637word32PrimTy :: Type
638word32PrimTy    = mkTyConTy word32PrimTyCon
639word32PrimTyCon :: TyCon
640word32PrimTyCon = pcPrimTyCon0 word32PrimTyConName Word32Rep
641
642word64PrimTy :: Type
643word64PrimTy    = mkTyConTy word64PrimTyCon
644word64PrimTyCon :: TyCon
645word64PrimTyCon = pcPrimTyCon0 word64PrimTyConName Word64Rep
646
647addrPrimTy :: Type
648addrPrimTy      = mkTyConTy addrPrimTyCon
649addrPrimTyCon :: TyCon
650addrPrimTyCon   = pcPrimTyCon0 addrPrimTyConName AddrRep
651
652floatPrimTy     :: Type
653floatPrimTy     = mkTyConTy floatPrimTyCon
654floatPrimTyCon :: TyCon
655floatPrimTyCon  = pcPrimTyCon0 floatPrimTyConName FloatRep
656
657doublePrimTy :: Type
658doublePrimTy    = mkTyConTy doublePrimTyCon
659doublePrimTyCon :: TyCon
660doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName DoubleRep
661
662{-
663************************************************************************
664*                                                                      *
665\subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
666*                                                                      *
667************************************************************************
668
669Note [The equality types story]
670~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
671GHC sports a veritable menagerie of equality types:
672
673         Type or  Lifted?  Hetero?  Role      Built in         Defining module
674         class?    L/U                        TyCon
675-----------------------------------------------------------------------------------------
676~#         T        U      hetero   nominal   eqPrimTyCon      GHC.Prim
677~~         C        L      hetero   nominal   heqTyCon         GHC.Types
678~          C        L      homo     nominal   eqTyCon          GHC.Types
679:~:        T        L      homo     nominal   (not built-in)   Data.Type.Equality
680:~~:       T        L      hetero   nominal   (not built-in)   Data.Type.Equality
681
682~R#        T        U      hetero   repr      eqReprPrimTy     GHC.Prim
683Coercible  C        L      homo     repr      coercibleTyCon   GHC.Types
684Coercion   T        L      homo     repr      (not built-in)   Data.Type.Coercion
685~P#        T        U      hetero   phantom   eqPhantPrimTyCon GHC.Prim
686
687Recall that "hetero" means the equality can related types of different
688kinds. Knowing that (t1 ~# t2) or (t1 ~R# t2) or even that (t1 ~P# t2)
689also means that (k1 ~# k2), where (t1 :: k1) and (t2 :: k2).
690
691To produce less confusion for end users, when not dumping and without
692-fprint-equality-relations, each of these groups is printed as the bottommost
693listed equality. That is, (~#) and (~~) are both rendered as (~) in
694error messages, and (~R#) is rendered as Coercible.
695
696Let's take these one at a time:
697
698    --------------------------
699    (~#) :: forall k1 k2. k1 -> k2 -> #
700    --------------------------
701This is The Type Of Equality in GHC. It classifies nominal coercions.
702This type is used in the solver for recording equality constraints.
703It responds "yes" to Type.isEqPrimPred and classifies as an EqPred in
704Type.classifyPredType.
705
706All wanted constraints of this type are built with coercion holes.
707(See Note [Coercion holes] in TyCoRep.) But see also
708Note [Deferred errors for coercion holes] in TcErrors to see how
709equality constraints are deferred.
710
711Within GHC, ~# is called eqPrimTyCon, and it is defined in TysPrim.
712
713
714    --------------------------
715    (~~) :: forall k1 k2. k1 -> k2 -> Constraint
716    --------------------------
717This is (almost) an ordinary class, defined as if by
718  class a ~# b => a ~~ b
719  instance a ~# b => a ~~ b
720Here's what's unusual about it:
721
722 * We can't actually declare it that way because we don't have syntax for ~#.
723   And ~# isn't a constraint, so even if we could write it, it wouldn't kind
724   check.
725
726 * Users cannot write instances of it.
727
728 * It is "naturally coherent". This means that the solver won't hesitate to
729   solve a goal of type (a ~~ b) even if there is, say (Int ~~ c) in the
730   context. (Normally, it waits to learn more, just in case the given
731   influences what happens next.) See Note [Naturally coherent classes]
732   in TcInteract.
733
734 * It always terminates. That is, in the UndecidableInstances checks, we
735   don't worry if a (~~) constraint is too big, as we know that solving
736   equality terminates.
737
738On the other hand, this behaves just like any class w.r.t. eager superclass
739unpacking in the solver. So a lifted equality given quickly becomes an unlifted
740equality given. This is good, because the solver knows all about unlifted
741equalities. There is some special-casing in TcInteract.matchClassInst to
742pretend that there is an instance of this class, as we can't write the instance
743in Haskell.
744
745Within GHC, ~~ is called heqTyCon, and it is defined in TysWiredIn.
746
747
748    --------------------------
749    (~) :: forall k. k -> k -> Constraint
750    --------------------------
751This is /exactly/ like (~~), except with a homogeneous kind.
752It is an almost-ordinary class defined as if by
753  class a ~# b => (a :: k) ~ (b :: k)
754  instance a ~# b => a ~ b
755
756 * All the bullets for (~~) apply
757
758 * In addition (~) is magical syntax, as ~ is a reserved symbol.
759   It cannot be exported or imported.
760
761Within GHC, ~ is called eqTyCon, and it is defined in TysWiredIn.
762
763Historical note: prior to July 18 (~) was defined as a
764  more-ordinary class with (~~) as a superclass.  But that made it
765  special in different ways; and the extra superclass selections to
766  get from (~) to (~#) via (~~) were tiresome.  Now it's defined
767  uniformly with (~~) and Coercible; much nicer.)
768
769
770    --------------------------
771    (:~:) :: forall k. k -> k -> *
772    (:~~:) :: forall k1 k2. k1 -> k2 -> *
773    --------------------------
774These are perfectly ordinary GADTs, wrapping (~) and (~~) resp.
775They are not defined within GHC at all.
776
777
778    --------------------------
779    (~R#) :: forall k1 k2. k1 -> k2 -> #
780    --------------------------
781The is the representational analogue of ~#. This is the type of representational
782equalities that the solver works on. All wanted constraints of this type are
783built with coercion holes.
784
785Within GHC, ~R# is called eqReprPrimTyCon, and it is defined in TysPrim.
786
787
788    --------------------------
789    Coercible :: forall k. k -> k -> Constraint
790    --------------------------
791This is quite like (~~) in the way it's defined and treated within GHC, but
792it's homogeneous. Homogeneity helps with type inference (as GHC can solve one
793kind from the other) and, in my (Richard's) estimation, will be more intuitive
794for users.
795
796An alternative design included HCoercible (like (~~)) and Coercible (like (~)).
797One annoyance was that we want `coerce :: Coercible a b => a -> b`, and
798we need the type of coerce to be fully wired-in. So the HCoercible/Coercible
799split required that both types be fully wired-in. Instead of doing this,
800I just got rid of HCoercible, as I'm not sure who would use it, anyway.
801
802Within GHC, Coercible is called coercibleTyCon, and it is defined in
803TysWiredIn.
804
805
806    --------------------------
807    Coercion :: forall k. k -> k -> *
808    --------------------------
809This is a perfectly ordinary GADT, wrapping Coercible. It is not defined
810within GHC at all.
811
812
813    --------------------------
814    (~P#) :: forall k1 k2. k1 -> k2 -> #
815    --------------------------
816This is the phantom analogue of ~# and it is barely used at all.
817(The solver has no idea about this one.) Here is the motivation:
818
819    data Phant a = MkPhant
820    type role Phant phantom
821
822    Phant <Int, Bool>_P :: Phant Int ~P# Phant Bool
823
824We just need to have something to put on that last line. You probably
825don't need to worry about it.
826
827
828
829Note [The State# TyCon]
830~~~~~~~~~~~~~~~~~~~~~~~
831State# is the primitive, unlifted type of states.  It has one type parameter,
832thus
833        State# RealWorld
834or
835        State# s
836
837where s is a type variable. The only purpose of the type parameter is to
838keep different state threads separate.  It is represented by nothing at all.
839
840The type parameter to State# is intended to keep separate threads separate.
841Even though this parameter is not used in the definition of State#, it is
842given role Nominal to enforce its intended use.
843-}
844
845mkStatePrimTy :: Type -> Type
846mkStatePrimTy ty = TyConApp statePrimTyCon [ty]
847
848statePrimTyCon :: TyCon   -- See Note [The State# TyCon]
849statePrimTyCon   = pcPrimTyCon statePrimTyConName [Nominal] VoidRep
850
851{-
852RealWorld is deeply magical.  It is *primitive*, but it is not
853*unlifted* (hence ptrArg).  We never manipulate values of type
854RealWorld; it's only used in the type system, to parameterise State#.
855-}
856
857realWorldTyCon :: TyCon
858realWorldTyCon = mkLiftedPrimTyCon realWorldTyConName [] liftedTypeKind []
859realWorldTy :: Type
860realWorldTy          = mkTyConTy realWorldTyCon
861realWorldStatePrimTy :: Type
862realWorldStatePrimTy = mkStatePrimTy realWorldTy        -- State# RealWorld
863
864-- Note: the ``state-pairing'' types are not truly primitive,
865-- so they are defined in \tr{TysWiredIn.hs}, not here.
866
867
868voidPrimTy :: Type
869voidPrimTy = TyConApp voidPrimTyCon []
870
871voidPrimTyCon :: TyCon
872voidPrimTyCon    = pcPrimTyCon voidPrimTyConName [] VoidRep
873
874mkProxyPrimTy :: Type -> Type -> Type
875mkProxyPrimTy k ty = TyConApp proxyPrimTyCon [k, ty]
876
877proxyPrimTyCon :: TyCon
878proxyPrimTyCon = mkPrimTyCon proxyPrimTyConName binders res_kind [Nominal,Phantom]
879  where
880     -- Kind: forall k. k -> TYPE (Tuple '[])
881     binders = mkTemplateTyConBinders [liftedTypeKind] id
882     res_kind = unboxedTupleKind []
883
884
885{- *********************************************************************
886*                                                                      *
887                Primitive equality constraints
888    See Note [The equality types story]
889*                                                                      *
890********************************************************************* -}
891
892eqPrimTyCon :: TyCon  -- The representation type for equality predicates
893                      -- See Note [The equality types story]
894eqPrimTyCon  = mkPrimTyCon eqPrimTyConName binders res_kind roles
895  where
896    -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
897    binders  = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
898    res_kind = unboxedTupleKind []
899    roles    = [Nominal, Nominal, Nominal, Nominal]
900
901-- like eqPrimTyCon, but the type for *Representational* coercions
902-- this should only ever appear as the type of a covar. Its role is
903-- interpreted in coercionRole
904eqReprPrimTyCon :: TyCon   -- See Note [The equality types story]
905eqReprPrimTyCon = mkPrimTyCon eqReprPrimTyConName binders res_kind roles
906  where
907    -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
908    binders  = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
909    res_kind = unboxedTupleKind []
910    roles    = [Nominal, Nominal, Representational, Representational]
911
912-- like eqPrimTyCon, but the type for *Phantom* coercions.
913-- This is only used to make higher-order equalities. Nothing
914-- should ever actually have this type!
915eqPhantPrimTyCon :: TyCon
916eqPhantPrimTyCon = mkPrimTyCon eqPhantPrimTyConName binders res_kind roles
917  where
918    -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
919    binders  = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
920    res_kind = unboxedTupleKind []
921    roles    = [Nominal, Nominal, Phantom, Phantom]
922
923-- | Given a Role, what TyCon is the type of equality predicates at that role?
924equalityTyCon :: Role -> TyCon
925equalityTyCon Nominal          = eqPrimTyCon
926equalityTyCon Representational = eqReprPrimTyCon
927equalityTyCon Phantom          = eqPhantPrimTyCon
928
929{- *********************************************************************
930*                                                                      *
931             The primitive array types
932*                                                                      *
933********************************************************************* -}
934
935arrayPrimTyCon, mutableArrayPrimTyCon, mutableByteArrayPrimTyCon,
936    byteArrayPrimTyCon, arrayArrayPrimTyCon, mutableArrayArrayPrimTyCon,
937    smallArrayPrimTyCon, smallMutableArrayPrimTyCon :: TyCon
938arrayPrimTyCon             = pcPrimTyCon arrayPrimTyConName             [Representational] UnliftedRep
939mutableArrayPrimTyCon      = pcPrimTyCon  mutableArrayPrimTyConName     [Nominal, Representational] UnliftedRep
940mutableByteArrayPrimTyCon  = pcPrimTyCon mutableByteArrayPrimTyConName  [Nominal] UnliftedRep
941byteArrayPrimTyCon         = pcPrimTyCon0 byteArrayPrimTyConName        UnliftedRep
942arrayArrayPrimTyCon        = pcPrimTyCon0 arrayArrayPrimTyConName       UnliftedRep
943mutableArrayArrayPrimTyCon = pcPrimTyCon mutableArrayArrayPrimTyConName [Nominal] UnliftedRep
944smallArrayPrimTyCon        = pcPrimTyCon smallArrayPrimTyConName        [Representational] UnliftedRep
945smallMutableArrayPrimTyCon = pcPrimTyCon smallMutableArrayPrimTyConName [Nominal, Representational] UnliftedRep
946
947mkArrayPrimTy :: Type -> Type
948mkArrayPrimTy elt           = TyConApp arrayPrimTyCon [elt]
949byteArrayPrimTy :: Type
950byteArrayPrimTy             = mkTyConTy byteArrayPrimTyCon
951mkArrayArrayPrimTy :: Type
952mkArrayArrayPrimTy = mkTyConTy arrayArrayPrimTyCon
953mkSmallArrayPrimTy :: Type -> Type
954mkSmallArrayPrimTy elt = TyConApp smallArrayPrimTyCon [elt]
955mkMutableArrayPrimTy :: Type -> Type -> Type
956mkMutableArrayPrimTy s elt  = TyConApp mutableArrayPrimTyCon [s, elt]
957mkMutableByteArrayPrimTy :: Type -> Type
958mkMutableByteArrayPrimTy s  = TyConApp mutableByteArrayPrimTyCon [s]
959mkMutableArrayArrayPrimTy :: Type -> Type
960mkMutableArrayArrayPrimTy s = TyConApp mutableArrayArrayPrimTyCon [s]
961mkSmallMutableArrayPrimTy :: Type -> Type -> Type
962mkSmallMutableArrayPrimTy s elt = TyConApp smallMutableArrayPrimTyCon [s, elt]
963
964
965{- *********************************************************************
966*                                                                      *
967                The mutable variable type
968*                                                                      *
969********************************************************************* -}
970
971mutVarPrimTyCon :: TyCon
972mutVarPrimTyCon = pcPrimTyCon mutVarPrimTyConName [Nominal, Representational] UnliftedRep
973
974mkMutVarPrimTy :: Type -> Type -> Type
975mkMutVarPrimTy s elt        = TyConApp mutVarPrimTyCon [s, elt]
976
977{-
978************************************************************************
979*                                                                      *
980\subsection[TysPrim-synch-var]{The synchronizing variable type}
981*                                                                      *
982************************************************************************
983-}
984
985mVarPrimTyCon :: TyCon
986mVarPrimTyCon = pcPrimTyCon mVarPrimTyConName [Nominal, Representational] UnliftedRep
987
988mkMVarPrimTy :: Type -> Type -> Type
989mkMVarPrimTy s elt          = TyConApp mVarPrimTyCon [s, elt]
990
991{-
992************************************************************************
993*                                                                      *
994\subsection[TysPrim-stm-var]{The transactional variable type}
995*                                                                      *
996************************************************************************
997-}
998
999tVarPrimTyCon :: TyCon
1000tVarPrimTyCon = pcPrimTyCon tVarPrimTyConName [Nominal, Representational] UnliftedRep
1001
1002mkTVarPrimTy :: Type -> Type -> Type
1003mkTVarPrimTy s elt = TyConApp tVarPrimTyCon [s, elt]
1004
1005{-
1006************************************************************************
1007*                                                                      *
1008\subsection[TysPrim-stable-ptrs]{The stable-pointer type}
1009*                                                                      *
1010************************************************************************
1011-}
1012
1013stablePtrPrimTyCon :: TyCon
1014stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConName [Representational] AddrRep
1015
1016mkStablePtrPrimTy :: Type -> Type
1017mkStablePtrPrimTy ty = TyConApp stablePtrPrimTyCon [ty]
1018
1019{-
1020************************************************************************
1021*                                                                      *
1022\subsection[TysPrim-stable-names]{The stable-name type}
1023*                                                                      *
1024************************************************************************
1025-}
1026
1027stableNamePrimTyCon :: TyCon
1028stableNamePrimTyCon = pcPrimTyCon stableNamePrimTyConName [Phantom] UnliftedRep
1029
1030mkStableNamePrimTy :: Type -> Type
1031mkStableNamePrimTy ty = TyConApp stableNamePrimTyCon [ty]
1032
1033{-
1034************************************************************************
1035*                                                                      *
1036\subsection[TysPrim-compact-nfdata]{The Compact NFData (CNF) type}
1037*                                                                      *
1038************************************************************************
1039-}
1040
1041compactPrimTyCon :: TyCon
1042compactPrimTyCon = pcPrimTyCon0 compactPrimTyConName UnliftedRep
1043
1044compactPrimTy :: Type
1045compactPrimTy = mkTyConTy compactPrimTyCon
1046
1047{-
1048************************************************************************
1049*                                                                      *
1050\subsection[TysPrim-BCOs]{The ``bytecode object'' type}
1051*                                                                      *
1052************************************************************************
1053-}
1054
1055bcoPrimTy    :: Type
1056bcoPrimTy    = mkTyConTy bcoPrimTyCon
1057bcoPrimTyCon :: TyCon
1058bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName UnliftedRep
1059
1060{-
1061************************************************************************
1062*                                                                      *
1063\subsection[TysPrim-Weak]{The ``weak pointer'' type}
1064*                                                                      *
1065************************************************************************
1066-}
1067
1068weakPrimTyCon :: TyCon
1069weakPrimTyCon = pcPrimTyCon weakPrimTyConName [Representational] UnliftedRep
1070
1071mkWeakPrimTy :: Type -> Type
1072mkWeakPrimTy v = TyConApp weakPrimTyCon [v]
1073
1074{-
1075************************************************************************
1076*                                                                      *
1077\subsection[TysPrim-thread-ids]{The ``thread id'' type}
1078*                                                                      *
1079************************************************************************
1080
1081A thread id is represented by a pointer to the TSO itself, to ensure
1082that they are always unique and we can always find the TSO for a given
1083thread id.  However, this has the unfortunate consequence that a
1084ThreadId# for a given thread is treated as a root by the garbage
1085collector and can keep TSOs around for too long.
1086
1087Hence the programmer API for thread manipulation uses a weak pointer
1088to the thread id internally.
1089-}
1090
1091threadIdPrimTy :: Type
1092threadIdPrimTy    = mkTyConTy threadIdPrimTyCon
1093threadIdPrimTyCon :: TyCon
1094threadIdPrimTyCon = pcPrimTyCon0 threadIdPrimTyConName UnliftedRep
1095
1096{-
1097************************************************************************
1098*                                                                      *
1099\subsection{SIMD vector types}
1100*                                                                      *
1101************************************************************************
1102-}
1103
1104#include "primop-vector-tys.hs-incl"
1105