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