2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrelVals]{Prelude values the compiler ``knows about''}
7 #include "HsVersions.h"
12 IMPORT_DELOOPER(IdLoop) ( UnfoldingGuidance(..), nullSpecEnv, SpecEnv )
13 import Id ( SYN_IE(Id), GenId, mkImported, mkUserId, mkTemplateLocals )
14 IMPORT_DELOOPER(PrelLoop)
22 import CmdLineOpts ( maybe_CompilingGhcInternals )
23 import CoreSyn -- quite a bit
24 import IdInfo -- quite a bit
25 import Literal ( mkMachInt )
26 import Name ( ExportFlag(..) )
28 import PrimOp ( PrimOp(..) )
29 import Type ( mkTyVarTy )
30 import TyVar ( openAlphaTyVar, alphaTyVar, betaTyVar, gammaTyVar )
31 import Unique -- lots of *Keys
37 pcMiscPrelId :: Unique{-IdKey-} -> FAST_STRING -> FAST_STRING -> Type -> IdInfo -> Id
39 pcMiscPrelId key m n ty info
41 name = mkWiredInName key (OrigName m n) ExportAll
42 imp = mkImported name ty info -- the usual case...
45 -- We lie and say the thing is imported; otherwise, we get into
46 -- a mess with dependency analysis; e.g., core2stg may heave in
47 -- random calls to GHCbase.unpackPS__. If GHCbase is the module
48 -- being compiled, then it's just a matter of luck if the definition
49 -- will be in "the right place" to be in scope.
52 %************************************************************************
54 \subsection[PrelVals-error-related]{@error@ and friends; @trace@}
56 %************************************************************************
58 GHC randomly injects these into the code.
60 @patError@ is just a version of @error@ for pattern-matching
61 failures. It knows various ``codes'' which expand to longer
62 strings---this saves space!
64 @absentErr@ is a thing we put in for ``absent'' arguments. They jolly
65 well shouldn't be yanked on, but if one is, then you will get a
66 friendly message from @absentErr@ (rather a totally random crash).
68 @parError@ is a special version of @error@ which the compiler does
69 not know to be a bottoming Id. It is used in the @_par_@ and @_seq_@
70 templates, but we don't ever expect to generate code for it.
73 pc_bottoming_Id key mod name ty
74 = pcMiscPrelId key mod name ty bottoming_info
76 bottoming_info = noIdInfo `addInfo` mkBottomStrictnessInfo
77 -- these "bottom" out, no matter what their arguments
80 = pc_bottoming_Id errorIdKey pRELUDE SLIT("error") errorTy
83 = pc_bottoming_Id u SLIT("GHCerr") n errorTy
86 = generic_ERROR_ID patErrorIdKey SLIT("patError")
88 = generic_ERROR_ID recConErrorIdKey SLIT("recConError")
90 = generic_ERROR_ID recUpdErrorIdKey SLIT("recUpdError")
92 = generic_ERROR_ID irrefutPatErrorIdKey SLIT("irrefutPatError")
93 nON_EXHAUSTIVE_GUARDS_ERROR_ID
94 = generic_ERROR_ID nonExhaustiveGuardsErrorIdKey SLIT("nonExhaustiveGuardsError")
95 nO_DEFAULT_METHOD_ERROR_ID
96 = generic_ERROR_ID noDefaultMethodErrorIdKey SLIT("noDefaultMethodError")
97 nO_EXPLICIT_METHOD_ERROR_ID
98 = generic_ERROR_ID nonExplicitMethodErrorIdKey SLIT("noExplicitMethodError")
101 = pc_bottoming_Id absentErrorIdKey SLIT("GHCerr") SLIT("absentErr")
102 (mkSigmaTy [openAlphaTyVar] [] openAlphaTy)
105 = pcMiscPrelId parErrorIdKey SLIT("GHCerr") SLIT("parError")
106 (mkSigmaTy [openAlphaTyVar] [] openAlphaTy) noIdInfo
108 openAlphaTy = mkTyVarTy openAlphaTyVar
111 errorTy = mkSigmaTy [openAlphaTyVar] [] (mkFunTys [mkListTy charTy] openAlphaTy)
112 -- Notice the openAlphaTyVar. It says that "error" can be applied
113 -- to unboxed as well as boxed types. This is OK because it never
114 -- returns, so the return type is irrelevant.
117 We want \tr{GHCbase.trace} to be wired in
118 because we don't want the strictness analyser to get ahold of it,
119 decide that the second argument is strict, evaluate that first (!!),
120 and make a jolly old mess.
123 = pcMiscPrelId traceIdKey gHC__ SLIT("trace") traceTy
124 (noIdInfo `addInfo` pcGenerateSpecs traceIdKey tRACE_ID noIdInfo traceTy)
126 traceTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [mkListTy charTy, alphaTy] alphaTy)
129 %************************************************************************
131 \subsection[PrelVals-Integer-support]{To support @Integer@ and @String@ literals}
133 %************************************************************************
137 = pcMiscPrelId packCStringIdKey{-ToDo:rename-} gHC__ SLIT("packStringForC__")
138 (mkFunTys [stringTy] byteArrayPrimTy) noIdInfo
140 --------------------------------------------------------------------
143 = pcMiscPrelId unpackCStringIdKey gHC__ SLIT("unpackPS__")
144 (mkFunTys [addrPrimTy{-a char *-}] stringTy) noIdInfo
146 -- (FunTy addrPrimTy{-a char *-} stringTy) (noIdInfo `addInfo` mkArityInfo 1)
147 -- but I don't like wired-in IdInfos (WDP)
149 unpackCString2Id -- for cases when a string has a NUL in it
150 = pcMiscPrelId unpackCString2IdKey gHC__ SLIT("unpackPS2__")
151 (mkFunTys [addrPrimTy{-a char *-}, intPrimTy{-length-}] stringTy)
154 --------------------------------------------------------------------
155 unpackCStringAppendId
156 = pcMiscPrelId unpackCStringAppendIdKey gHC__ SLIT("unpackAppendPS__")
157 (mkFunTys [addrPrimTy{-a "char *" pointer-},stringTy] stringTy)
159 {-LATER:`addInfo_UF` mkMagicUnfolding unpackCStringAppendIdKey-})
160 `addInfo` mkArityInfo 2)
163 = pcMiscPrelId unpackCStringFoldrIdKey gHC__ SLIT("unpackFoldrPS__")
164 (mkSigmaTy [alphaTyVar] []
165 (mkFunTys [addrPrimTy{-a "char *" pointer-},
166 mkFunTys [charTy, alphaTy] alphaTy,
170 {-LATER:`addInfo_UF` mkMagicUnfolding unpackCStringFoldrIdKey-})
171 `addInfo` mkArityInfo 3)
174 OK, this is Will's idea: we should have magic values for Integers 0,
175 +1, +2, and -1 (go ahead, fire me):
178 = pcMiscPrelId integerZeroIdKey gHC__ SLIT("integer_0") integerTy noIdInfo
180 = pcMiscPrelId integerPlusOneIdKey gHC__ SLIT("integer_1") integerTy noIdInfo
182 = pcMiscPrelId integerPlusTwoIdKey gHC__ SLIT("integer_2") integerTy noIdInfo
184 = pcMiscPrelId integerMinusOneIdKey gHC__ SLIT("integer_m1") integerTy noIdInfo
187 %************************************************************************
189 \subsection[PrelVals-parallel]{@seq@ and @par@: for parallel operation (only)}
191 %************************************************************************
195 --------------------------------------------------------------------
196 -- seqId :: "seq", used w/ GRIP, etc., is really quite similar to
200 seq = /\ a b -> \ x y -> case x of { _ -> y }
203 seq = /\ a b -> \ x y -> case seq# x y of { _Lift y' -> y' }
206 seq = /\ a b -> \ x::a y::b -> case seq# x of { 0# -> parError#; _ -> y; }
210 seqId = pcMiscPrelId seqIdKey gHC__ SLIT("seq")
211 (mkSigmaTy [alphaTyVar, betaTyVar] []
212 (mkFunTys [alphaTy, betaTy] betaTy))
213 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding seq_template))
223 = mkLam [alphaTyVar, betaTyVar] [x, y] (
224 Case (Prim SeqOp [TyArg alphaTy, VarArg x]) (
226 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
227 (BindDefault z (Var y))))
229 --------------------------------------------------------------------
230 -- parId :: "par", also used w/ GRIP, etc.
234 par = /\ a b -> \ x y -> case (par# (case x of { _ -> () })) of { _ -> y }
238 par = /\ a b -> \ x y -> case par# x y of { _Lift y' -> y' }
242 par = /\ a b -> \ x::a y::b -> case par# x of { 0# -> parError#; _ -> y; }
245 parId = pcMiscPrelId parIdKey gHC__ SLIT("par")
246 (mkSigmaTy [alphaTyVar, betaTyVar] []
247 (mkFunTys [alphaTy, betaTy] betaTy))
248 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding par_template))
258 = mkLam [alphaTyVar, betaTyVar] [x, y] (
259 Case (Prim ParOp [TyArg alphaTy, VarArg x]) (
261 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
262 (BindDefault z (Var y))))
264 -- forkId :: "fork", for *required* concurrent threads
266 _fork_ = /\ a b -> \ x::a y::b -> case fork# x of { 0# -> parError#; _ -> y; }
268 forkId = pcMiscPrelId forkIdKey gHC__ SLIT("fork")
269 (mkSigmaTy [alphaTyVar, betaTyVar] []
270 (mkFunTys [alphaTy, betaTy] betaTy))
271 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding fork_template))
281 = mkLam [alphaTyVar, betaTyVar] [x, y] (
282 Case (Prim ForkOp [TyArg alphaTy, VarArg x]) (
284 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
285 (BindDefault z (Var y))))
292 parLocalId = pcMiscPrelId parLocalIdKey gHC__ SLIT("parLocal")
293 (mkSigmaTy [alphaTyVar, betaTyVar] []
294 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
295 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parLocal_template))
297 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
298 [w, g, s, p, x, y, z]
310 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, x, y] (
311 Case (Prim ParLocalOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
313 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
314 (BindDefault z (Var y))))
316 parGlobalId = pcMiscPrelId parGlobalIdKey gHC__ SLIT("parGlobal")
317 (mkSigmaTy [alphaTyVar, betaTyVar] []
318 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
319 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parGlobal_template))
321 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
322 [w, g, s, p, x, y, z]
334 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, x, y] (
335 Case (Prim ParGlobalOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
337 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
338 (BindDefault z (Var y))))
341 parAtId = pcMiscPrelId parAtIdKey gHC__ SLIT("parAt")
342 (mkSigmaTy [alphaTyVar, betaTyVar] []
343 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy,
344 alphaTy, betaTy, gammaTy] gammaTy))
345 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAt_template))
347 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
348 [w, g, s, p, v, x, y, z]
361 = mkLam [alphaTyVar, betaTyVar, gammaTyVar] [w, g, s, p, v, x, y] (
362 Case (Prim ParAtOp [TyArg alphaTy, TyArg betaTy, TyArg gammaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
364 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [gammaTy])]
365 (BindDefault z (Var y))))
367 parAtAbsId = pcMiscPrelId parAtAbsIdKey gHC__ SLIT("parAtAbs")
368 (mkSigmaTy [alphaTyVar, betaTyVar] []
369 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
370 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtAbs_template))
372 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
373 [w, g, s, p, v, x, y, z]
386 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, v, x, y] (
387 Case (Prim ParAtAbsOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
389 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
390 (BindDefault z (Var y))))
392 parAtRelId = pcMiscPrelId parAtRelIdKey gHC__ SLIT("parAtRel")
393 (mkSigmaTy [alphaTyVar, betaTyVar] []
394 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
395 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtRel_template))
397 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
398 [w, g, s, p, v, x, y, z]
411 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, v, x, y] (
412 Case (Prim ParAtRelOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
414 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
415 (BindDefault z (Var y))))
417 parAtForNowId = pcMiscPrelId parAtForNowIdKey gHC__ SLIT("parAtForNow")
418 (mkSigmaTy [alphaTyVar, betaTyVar] []
419 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy,
420 alphaTy, betaTy, gammaTy] gammaTy))
421 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtForNow_template))
423 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
424 [w, g, s, p, v, x, y, z]
437 = mkLam [alphaTyVar, betaTyVar, gammaTyVar] [w, g, s, p, v, x, y] (
438 Case (Prim ParAtForNowOp [TyArg alphaTy, TyArg betaTy, TyArg gammaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
440 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [gammaTy])]
441 (BindDefault z (Var y))))
443 -- copyable and noFollow are currently merely hooks: they are translated into
444 -- calls to the macros COPYABLE and NOFOLLOW -- HWL
446 copyableId = pcMiscPrelId copyableIdKey gHC__ SLIT("copyable")
447 (mkSigmaTy [alphaTyVar] []
449 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding copyable_template))
451 -- Annotations: x: closure that's tagged to by copyable
459 = mkLam [alphaTyVar] [x] ( Prim CopyableOp [TyArg alphaTy, VarArg x] )
461 noFollowId = pcMiscPrelId noFollowIdKey gHC__ SLIT("noFollow")
462 (mkSigmaTy [alphaTyVar] []
464 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding noFollow_template))
466 -- Annotations: x: closure that's tagged to not follow
474 = mkLam [alphaTyVar] [x] ( Prim NoFollowOp [TyArg alphaTy, VarArg x] )
478 %************************************************************************
480 \subsection[PrelVals-runST]{@runST@: Magic start-state-transformer function}
482 %************************************************************************
484 @runST@ has a non-Haskell-able type:
486 -- runST :: forall a. (forall s. _ST s a) -> a
487 -- which is to say ::
488 -- forall a. (forall s. (_State s -> (a, _State s))) -> a
490 runST a m = case m _RealWorld (S# _RealWorld realWorld#) of
491 (r :: a, wild :: _State _RealWorld) -> r
494 We unfold always, just for simplicity:
497 = pcMiscPrelId runSTIdKey gHC__ SLIT("runST") run_ST_ty id_info
502 st_ty a = mkSigmaTy [s_tv] [] (mkStateTransformerTy s a)
505 = mkSigmaTy [alphaTyVar] [] (mkFunTys [st_ty alphaTy] alphaTy)
506 -- NB: rank-2 polymorphism! (forall inside the st_ty...)
510 `addInfo` mkArityInfo 1
511 `addInfo` mkStrictnessInfo [WwStrict] Nothing
512 `addInfo` mkArgUsageInfo [ArgUsage 1]
513 -- ABSOLUTELY NO UNFOLDING, e.g.: (mkUnfolding EssentialUnfolding run_ST_template)
519 {-t-} realWorldStateTy,
521 {-_-} realWorldStateTy
525 = mkLam [alphaTyVar] [m] (
526 Let (NonRec t (Con stateDataCon [TyArg realWorldTy, VarArg realWorldPrimId])) (
527 Case (App (mkTyApp (Var m) [realWorldTy]) (VarArg t)) (
529 [(mkTupleCon 2, [r, wild], Var r)]
534 SLPJ 95/04: Why @runST@ must not have an unfolding; consider:
538 (a, s') = newArray# 100 [] s
539 (_, s'') = fill_in_array_or_something a x s'
543 If we inline @runST@, we'll get:
546 (a, s') = newArray# 100 [] realWorld#{-NB-}
547 (_, s'') = fill_in_array_or_something a x s'
551 And now the @newArray#@ binding can be floated to become a CAF, which
552 is totally and utterly wrong:
555 (a, s') = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!
558 let (_, s'') = fill_in_array_or_something a x s' in
561 All calls to @f@ will share a {\em single} array! End SLPJ 95/04.
563 @realWorld#@ used to be a magic literal, \tr{void#}. If things get
564 nasty as-is, change it back to a literal (@Literal@).
567 = pcMiscPrelId realWorldPrimIdKey gHC_BUILTINS SLIT("realWorld#")
573 voidId = pcMiscPrelId voidIdKey gHC_BUILTINS SLIT("void") voidTy noIdInfo
576 %************************************************************************
578 \subsection[PrelVals-foldr-build]{Values known about for ``foldr/build''}
580 %************************************************************************
584 = pcMiscPrelId buildIdKey SLIT("GHCerr") SLIT("build") buildTy
586 {-LATER:`addInfo_UF` mkMagicUnfolding buildIdKey-})
587 `addInfo` mkStrictnessInfo [WwStrict] Nothing)
588 `addInfo` mkArgUsageInfo [ArgUsage 2])
589 `addInfo` pcGenerateSpecs buildIdKey buildId noIdInfo{-ToDo-} buildTy)
590 -- cheating, but since _build never actually exists ...
592 -- The type of this strange object is:
593 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a]
595 buildTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [build_ty] (mkListTy alphaTy))
597 build_ty = mkSigmaTy [betaTyVar] []
598 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy] betaTy)
601 @mkBuild@ is sugar for building a build!
603 @mkbuild ty tv c n e@ $Rightarrow$ @build ty (/\ tv -> \ c n -> e)@
604 @ty@ is the type of the list.
605 @tv@ is always a new type variable.
606 @c,n@ are Id's for the abstract cons and nil, @g@ for let binding the argument argument.
609 v :: (\/ b . (a -> b -> b) -> b -> b) -> [a]
610 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a]
611 @e@ is the object right inside the @build@
619 -> CoreExpr -- template
620 -> CoreExpr -- template
622 mkBuild ty tv c n g expr
623 = Let (NonRec g (mkLam [tv] [c,n] expr))
624 (App (mkTyApp (Var buildId) [ty]) (VarArg g))
629 = pcMiscPrelId augmentIdKey SLIT("GHCerr") SLIT("augment") augmentTy
631 {-LATER:`addInfo_UF` mkMagicUnfolding augmentIdKey-})
632 `addInfo` mkStrictnessInfo [WwStrict,WwLazy False] Nothing)
633 `addInfo` mkArgUsageInfo [ArgUsage 2,UnknownArgUsage])
634 -- cheating, but since _augment never actually exists ...
636 -- The type of this strange object is:
637 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a] -> [a]
639 augmentTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [aug_ty, mkListTy alphaTy] (mkListTy alphaTy))
641 aug_ty = mkSigmaTy [betaTyVar] []
642 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy] betaTy)
646 foldrId = pcMiscPrelId foldrIdKey pRELUDE SLIT("foldr")
650 mkSigmaTy [alphaTyVar, betaTyVar] []
651 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy, mkListTy alphaTy] betaTy)
653 idInfo = (((((noIdInfo
654 {-LATER:`addInfo_UF` mkMagicUnfolding foldrIdKey-})
655 `addInfo` mkStrictnessInfo [WwLazy False,WwLazy False,WwStrict] Nothing)
656 `addInfo` mkArityInfo 3)
657 `addInfo` mkUpdateInfo [2,2,1])
658 `addInfo` pcGenerateSpecs foldrIdKey foldrId noIdInfo{-ToDo-} foldrTy)
660 foldlId = pcMiscPrelId foldlIdKey pRELUDE SLIT("foldl")
664 mkSigmaTy [alphaTyVar, betaTyVar] []
665 (mkFunTys [mkFunTys [alphaTy, betaTy] alphaTy, alphaTy, mkListTy betaTy] alphaTy)
667 idInfo = (((((noIdInfo
668 {-LATER:`addInfo_UF` mkMagicUnfolding foldlIdKey-})
669 `addInfo` mkStrictnessInfo [WwLazy False,WwLazy False,WwStrict] Nothing)
670 `addInfo` mkArityInfo 3)
671 `addInfo` mkUpdateInfo [2,2,1])
672 `addInfo` pcGenerateSpecs foldlIdKey foldlId noIdInfo{-ToDo-} foldlTy)
674 -- A bit of magic goes no here. We translate appendId into ++,
675 -- you have to be carefull when you actually compile append:
676 -- xs ++ ys = augment (\ c n -> foldr c n xs) ys
677 -- {- unfold augment -}
679 -- {- fold foldr to append -}
680 -- = ys `appendId` xs
681 -- = ys ++ xs -- ugg!
682 -- *BUT* you want (++) and not _append in your interfaces.
684 -- So you have to turn *off* unfolding of foldr inside FoldrBuild.hs inside
687 {- OLD: doesn't apply with 1.3
689 = pcMiscPrelId appendIdKey pRELUDE_LIST SLIT("++") appendTy idInfo
692 (mkSigmaTy [alphaTyVar] []
693 (mkFunTys [mkListTy alphaTy, mkListTy alphaTy] (mkListTy alphaTy)))
695 `addInfo` mkStrictnessInfo [WwStrict,WwLazy False] Nothing)
696 `addInfo` mkArityInfo 2)
697 `addInfo` mkUpdateInfo [1,2])
701 %************************************************************************
703 \subsection[PrelUtils-specialisations]{Specialisations for builtin values}
705 %************************************************************************
707 The specialisations which exist for the builtin values must be recorded in
710 NOTE: THE USES OF THE pcGenerate... FUNCTIONS MUST CORRESPOND
711 TO THE SPECIALISATIONS DECLARED IN THE PRELUDE !!!
713 HACK: We currently use the same unique for the specialised Ids.
715 The list @specing_types@ determines the types for which specialised
716 versions are created. Note: This should correspond with the
717 types passed to the pre-processor with the -genSPECS arg (see ghc.lprl).
719 ToDo: Create single mkworld definition which is grabbed here and in ghc.lprl
722 pcGenerateSpecs :: Unique -> Id -> IdInfo -> Type -> SpecEnv
723 pcGenerateSpecs key id info ty
728 pc_gen_specs True key id info ty
730 pc_gen_specs is_id key id info ty
731 = mkSpecEnv spec_infos
733 spec_infos = [ let spec_ty = specialiseTy ty spec_tys 0
735 then mkSpecId key {- HACK WARNING: same unique! -}
736 id spec_tys spec_ty info
737 else panic "SpecData:SpecInfo:SpecId"
739 SpecInfo spec_tys (length ctxts) spec_id
740 | spec_tys <- specialisations ]
742 (tyvars, ctxts, _) = splitSigmaTy ty
743 no_tyvars = length tyvars
745 specialisations = if no_tyvars == 0
747 else tail (cross_product no_tyvars specing_types)
749 -- N.B. tail removes fully polymorphic specialisation
751 cross_product 0 tys = []
752 cross_product 1 tys = map (:[]) tys
753 cross_product n tys = concat [map (:cp) tys | cp <- cross_product (n-1) tys]
756 specing_types = [Nothing,