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