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