2 % (c) The AQUA Project, Glasgow University, 1998
4 \section[StdIdInfo]{Standard unfoldings}
6 This module contains definitions for the IdInfo for things that
7 have a standard form, namely:
11 * method and superclass selectors
12 * primitive operations
16 mkDictFunId, mkDefaultMethodId,
21 mkPrimOpId, mkFCallId,
23 mkReboxingAlt, wrapNewTypeBody, unwrapNewTypeBody,
24 mkUnpackCase, mkProductBox,
26 -- And some particular Ids; see below for why they are wired in
27 wiredInIds, ghcPrimIds,
28 unsafeCoerceId, realWorldPrimId, voidArgId, nullAddrId, seqId,
29 lazyId, lazyIdUnfolding, lazyIdKey,
32 rEC_CON_ERROR_ID, iRREFUT_PAT_ERROR_ID, rUNTIME_ERROR_ID,
33 nON_EXHAUSTIVE_GUARDS_ERROR_ID, nO_METHOD_BINDING_ERROR_ID,
34 pAT_ERROR_ID, eRROR_ID,
39 #include "HsVersions.h"
42 import BasicTypes ( Arity, StrictnessMark(..), isMarkedUnboxed, isMarkedStrict )
43 import Rules ( mkSpecInfo )
44 import TysPrim ( openAlphaTyVars, alphaTyVar, alphaTy,
45 realWorldStatePrimTy, addrPrimTy
47 import TysWiredIn ( charTy, mkListTy )
48 import PrelRules ( primOpRules )
49 import Type ( TyThing(..), mkForAllTy, tyVarsOfTypes,
50 newTyConInstRhs, mkTopTvSubst, substTyVar, substTy )
51 import TcGadt ( gadtRefine, refineType, emptyRefinement )
52 import HsBinds ( ExprCoFn(..), isIdCoercion )
53 import Coercion ( mkSymCoercion, mkUnsafeCoercion, isEqPred )
54 import TcType ( Type, ThetaType, mkDictTy, mkPredTys, mkPredTy,
55 mkTyConApp, mkTyVarTys, mkClassPred, isPredTy,
56 mkFunTys, mkFunTy, mkSigmaTy, tcSplitSigmaTy, tcEqType,
57 isUnLiftedType, mkForAllTys, mkTyVarTy, tyVarsOfType,
58 tcSplitFunTys, tcSplitForAllTys, dataConsStupidTheta
60 import CoreUtils ( exprType, dataConOrigInstPat, mkCoerce )
61 import CoreUnfold ( mkTopUnfolding, mkCompulsoryUnfolding )
62 import Literal ( nullAddrLit, mkStringLit )
63 import TyCon ( TyCon, isNewTyCon, tyConDataCons, FieldLabel,
64 tyConStupidTheta, isProductTyCon, isDataTyCon,
65 isRecursiveTyCon, isFamInstTyCon,
66 tyConFamInst_maybe, tyConFamilyCoercion_maybe,
68 import Class ( Class, classTyCon, classSelIds )
69 import Var ( Id, TyVar, Var, setIdType )
70 import VarSet ( isEmptyVarSet, subVarSet, varSetElems )
71 import Name ( mkFCallName, mkWiredInName, Name, BuiltInSyntax(..))
72 import OccName ( mkOccNameFS, varName )
73 import PrimOp ( PrimOp, primOpSig, primOpOcc, primOpTag )
74 import ForeignCall ( ForeignCall )
75 import DataCon ( DataCon, DataConIds(..), dataConTyCon,
77 dataConFieldLabels, dataConRepArity, dataConResTys,
78 dataConRepArgTys, dataConRepType, dataConFullSig,
79 dataConStrictMarks, dataConExStricts,
80 splitProductType, isVanillaDataCon, dataConFieldType,
83 import Id ( idType, mkGlobalId, mkVanillaGlobal, mkSysLocal,
84 mkTemplateLocals, mkTemplateLocalsNum, mkExportedLocalId,
85 mkTemplateLocal, idName
87 import IdInfo ( IdInfo, noCafIdInfo, setUnfoldingInfo,
88 setArityInfo, setSpecInfo, setCafInfo,
89 setAllStrictnessInfo, vanillaIdInfo,
90 GlobalIdDetails(..), CafInfo(..)
92 import NewDemand ( mkStrictSig, DmdResult(..),
93 mkTopDmdType, topDmd, evalDmd, lazyDmd, retCPR,
94 Demand(..), Demands(..) )
95 import DmdAnal ( dmdAnalTopRhs )
97 import Unique ( mkBuiltinUnique, mkPrimOpIdUnique )
98 import Maybe ( fromJust )
101 import Util ( dropList, isSingleton )
104 import ListSetOps ( assoc, minusList )
107 %************************************************************************
109 \subsection{Wired in Ids}
111 %************************************************************************
115 = [ -- These error-y things are wired in because we don't yet have
116 -- a way to express in an interface file that the result type variable
117 -- is 'open'; that is can be unified with an unboxed type
119 -- [The interface file format now carry such information, but there's
120 -- no way yet of expressing at the definition site for these
121 -- error-reporting functions that they have an 'open'
122 -- result type. -- sof 1/99]
124 eRROR_ID, -- This one isn't used anywhere else in the compiler
125 -- But we still need it in wiredInIds so that when GHC
126 -- compiles a program that mentions 'error' we don't
127 -- import its type from the interface file; we just get
128 -- the Id defined here. Which has an 'open-tyvar' type.
131 iRREFUT_PAT_ERROR_ID,
132 nON_EXHAUSTIVE_GUARDS_ERROR_ID,
133 nO_METHOD_BINDING_ERROR_ID,
140 -- These Ids are exported from GHC.Prim
142 = [ -- These can't be defined in Haskell, but they have
143 -- perfectly reasonable unfoldings in Core
151 %************************************************************************
153 \subsection{Data constructors}
155 %************************************************************************
157 The wrapper for a constructor is an ordinary top-level binding that evaluates
158 any strict args, unboxes any args that are going to be flattened, and calls
161 We're going to build a constructor that looks like:
163 data (Data a, C b) => T a b = T1 !a !Int b
166 \d1::Data a, d2::C b ->
167 \p q r -> case p of { p ->
169 Con T1 [a,b] [p,q,r]}}
173 * d2 is thrown away --- a context in a data decl is used to make sure
174 one *could* construct dictionaries at the site the constructor
175 is used, but the dictionary isn't actually used.
177 * We have to check that we can construct Data dictionaries for
178 the types a and Int. Once we've done that we can throw d1 away too.
180 * We use (case p of q -> ...) to evaluate p, rather than "seq" because
181 all that matters is that the arguments are evaluated. "seq" is
182 very careful to preserve evaluation order, which we don't need
185 You might think that we could simply give constructors some strictness
186 info, like PrimOps, and let CoreToStg do the let-to-case transformation.
187 But we don't do that because in the case of primops and functions strictness
188 is a *property* not a *requirement*. In the case of constructors we need to
189 do something active to evaluate the argument.
191 Making an explicit case expression allows the simplifier to eliminate
192 it in the (common) case where the constructor arg is already evaluated.
194 [Wrappers for data instance tycons]
195 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196 In the case of data instances, the wrapper also applies the coercion turning
197 the representation type into the family instance type to cast the result of
198 the wrapper. For example, consider the declarations
200 data family Map k :: * -> *
201 data instance Map (a, b) v = MapPair (Map a (Pair b v))
203 The tycon to which the datacon MapPair belongs gets a unique internal name of
204 the form :R123Map, and we call it the representation tycon. In contrast, Map
205 is the family tycon (accessible via tyConFamInst_maybe). The wrapper and work
206 of MapPair get the types
208 $WMapPair :: forall a b v. Map a (Map a b v) -> Map (a, b) v
209 $wMapPair :: forall a b v. Map a (Map a b v) -> :R123Map a b v
211 which implies that the wrapper code will have to apply the coercion moving
212 between representation and family type. It is accessible via
213 tyConFamilyCoercion_maybe and has kind
215 Co123Map a b v :: {Map (a, b) v :=: :R123Map a b v}
217 This coercion is conditionally applied by wrapFamInstBody.
220 mkDataConIds :: Name -> Name -> DataCon -> DataConIds
221 mkDataConIds wrap_name wkr_name data_con
223 = DCIds Nothing nt_work_id -- Newtype, only has a worker
225 | any isMarkedStrict all_strict_marks -- Algebraic, needs wrapper
226 || not (null eq_spec)
227 || isFamInstTyCon tycon
228 = DCIds (Just alg_wrap_id) wrk_id
230 | otherwise -- Algebraic, no wrapper
231 = DCIds Nothing wrk_id
233 (univ_tvs, ex_tvs, eq_spec,
234 theta, orig_arg_tys) = dataConFullSig data_con
235 tycon = dataConTyCon data_con
237 ----------- Wrapper --------------
238 -- We used to include the stupid theta in the wrapper's args
239 -- but now we don't. Instead the type checker just injects these
240 -- extra constraints where necessary.
241 wrap_tvs = (univ_tvs `minusList` map fst eq_spec) ++ ex_tvs
242 subst = mkTopTvSubst eq_spec
243 dict_tys = mkPredTys theta
244 result_ty_args = map (substTyVar subst) univ_tvs
245 result_ty = case tyConFamInst_maybe tycon of
246 -- ordinary constructor
247 Nothing -> mkTyConApp tycon result_ty_args
248 -- family instance constructor
251 mkTyConApp familyTyCon (map (substTy subst) instTys)
252 wrap_ty = mkForAllTys wrap_tvs $ mkFunTys dict_tys $
253 mkFunTys orig_arg_tys $ result_ty
254 -- NB: watch out here if you allow user-written equality
255 -- constraints in data constructor signatures
257 ----------- Worker (algebraic data types only) --------------
258 -- The *worker* for the data constructor is the function that
259 -- takes the representation arguments and builds the constructor.
260 wrk_id = mkGlobalId (DataConWorkId data_con) wkr_name
261 (dataConRepType data_con) wkr_info
263 wkr_arity = dataConRepArity data_con
264 wkr_info = noCafIdInfo
265 `setArityInfo` wkr_arity
266 `setAllStrictnessInfo` Just wkr_sig
267 `setUnfoldingInfo` evaldUnfolding -- Record that it's evaluated,
270 wkr_sig = mkStrictSig (mkTopDmdType (replicate wkr_arity topDmd) cpr_info)
271 -- Notice that we do *not* say the worker is strict
272 -- even if the data constructor is declared strict
273 -- e.g. data T = MkT !(Int,Int)
274 -- Why? Because the *wrapper* is strict (and its unfolding has case
275 -- expresssions that do the evals) but the *worker* itself is not.
276 -- If we pretend it is strict then when we see
277 -- case x of y -> $wMkT y
278 -- the simplifier thinks that y is "sure to be evaluated" (because
279 -- $wMkT is strict) and drops the case. No, $wMkT is not strict.
281 -- When the simplifer sees a pattern
282 -- case e of MkT x -> ...
283 -- it uses the dataConRepStrictness of MkT to mark x as evaluated;
284 -- but that's fine... dataConRepStrictness comes from the data con
285 -- not from the worker Id.
287 cpr_info | isProductTyCon tycon &&
290 wkr_arity <= mAX_CPR_SIZE = retCPR
292 -- RetCPR is only true for products that are real data types;
293 -- that is, not unboxed tuples or [non-recursive] newtypes
295 ----------- Workers for newtypes --------------
296 nt_work_id = mkGlobalId (DataConWrapId data_con) wkr_name wrap_ty nt_work_info
297 nt_work_info = noCafIdInfo -- The NoCaf-ness is set by noCafIdInfo
298 `setArityInfo` 1 -- Arity 1
299 `setUnfoldingInfo` newtype_unf
300 newtype_unf = ASSERT( isVanillaDataCon data_con &&
301 isSingleton orig_arg_tys )
302 -- No existentials on a newtype, but it can have a context
303 -- e.g. newtype Eq a => T a = MkT (...)
304 mkCompulsoryUnfolding $
305 mkLams wrap_tvs $ Lam id_arg1 $
306 wrapNewTypeBody tycon result_ty_args
309 id_arg1 = mkTemplateLocal 1 (head orig_arg_tys)
311 ----------- Wrappers for algebraic data types --------------
312 alg_wrap_id = mkGlobalId (DataConWrapId data_con) wrap_name wrap_ty alg_wrap_info
313 alg_wrap_info = noCafIdInfo -- The NoCaf-ness is set by noCafIdInfo
314 `setArityInfo` alg_arity
315 -- It's important to specify the arity, so that partial
316 -- applications are treated as values
317 `setUnfoldingInfo` alg_unf
318 `setAllStrictnessInfo` Just wrap_sig
320 all_strict_marks = dataConExStricts data_con ++ dataConStrictMarks data_con
321 wrap_sig = mkStrictSig (mkTopDmdType arg_dmds cpr_info)
322 arg_dmds = map mk_dmd all_strict_marks
323 mk_dmd str | isMarkedStrict str = evalDmd
324 | otherwise = lazyDmd
325 -- The Cpr info can be important inside INLINE rhss, where the
326 -- wrapper constructor isn't inlined.
327 -- And the argument strictness can be important too; we
328 -- may not inline a contructor when it is partially applied.
330 -- data W = C !Int !Int !Int
331 -- ...(let w = C x in ...(w p q)...)...
332 -- we want to see that w is strict in its two arguments
334 alg_unf = mkTopUnfolding $ Note InlineMe $
336 mkLams dict_args $ mkLams id_args $
337 foldr mk_case con_app
338 (zip (dict_args ++ id_args) all_strict_marks)
341 con_app _ rep_ids = wrapFamInstBody tycon result_ty_args $
342 Var wrk_id `mkTyApps` result_ty_args
344 `mkTyApps` map snd eq_spec
345 `mkVarApps` reverse rep_ids
347 (dict_args,i2) = mkLocals 1 dict_tys
348 (id_args,i3) = mkLocals i2 orig_arg_tys
352 :: (Id, StrictnessMark) -- Arg, strictness
353 -> (Int -> [Id] -> CoreExpr) -- Body
354 -> Int -- Next rep arg id
355 -> [Id] -- Rep args so far, reversed
357 mk_case (arg,strict) body i rep_args
359 NotMarkedStrict -> body i (arg:rep_args)
361 | isUnLiftedType (idType arg) -> body i (arg:rep_args)
363 Case (Var arg) arg result_ty [(DEFAULT,[], body i (arg:rep_args))]
366 -> unboxProduct i (Var arg) (idType arg) the_body
368 the_body i con_args = body i (reverse con_args ++ rep_args)
370 mAX_CPR_SIZE :: Arity
372 -- We do not treat very big tuples as CPR-ish:
373 -- a) for a start we get into trouble because there aren't
374 -- "enough" unboxed tuple types (a tiresome restriction,
376 -- b) more importantly, big unboxed tuples get returned mainly
377 -- on the stack, and are often then allocated in the heap
378 -- by the caller. So doing CPR for them may in fact make
381 mkLocals i tys = (zipWith mkTemplateLocal [i..i+n-1] tys, i+n)
385 -- If the type constructor is a representation type of a data instance, wrap
386 -- the expression into a cast adjusting the expression type, which is an
387 -- instance of the representation type, to the corresponding instance of the
388 -- family instance type.
390 wrapFamInstBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
391 wrapFamInstBody tycon args result_expr
392 | Just co_con <- tyConFamilyCoercion_maybe tycon
393 = mkCoerce (mkSymCoercion (mkTyConApp co_con args)) result_expr
397 -- Apply the coercion in the opposite direction.
399 unwrapFamInstBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
400 unwrapFamInstBody tycon args result_expr
401 | Just co_con <- tyConFamilyCoercion_maybe tycon
402 = mkCoerce (mkTyConApp co_con args) result_expr
409 %************************************************************************
411 \subsection{Record selectors}
413 %************************************************************************
415 We're going to build a record selector unfolding that looks like this:
417 data T a b c = T1 { ..., op :: a, ...}
418 | T2 { ..., op :: a, ...}
421 sel = /\ a b c -> \ d -> case d of
426 Similarly for newtypes
428 newtype N a = MkN { unN :: a->a }
431 unN n = coerce (a->a) n
433 We need to take a little care if the field has a polymorphic type:
435 data R = R { f :: forall a. a->a }
439 f :: forall a. R -> a -> a
440 f = /\ a \ r = case r of
443 (not f :: R -> forall a. a->a, which gives the type inference mechanism
444 problems at call sites)
446 Similarly for (recursive) newtypes
448 newtype N = MkN { unN :: forall a. a->a }
450 unN :: forall b. N -> b -> b
451 unN = /\b -> \n:N -> (coerce (forall a. a->a) n)
454 Note [Naughty record selectors]
455 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456 A "naughty" field is one for which we can't define a record
457 selector, because an existential type variable would escape. For example:
458 data T = forall a. MkT { x,y::a }
459 We obviously can't define
461 Nevertheless we *do* put a RecordSelId into the type environment
462 so that if the user tries to use 'x' as a selector we can bleat
463 helpfully, rather than saying unhelpfully that 'x' is not in scope.
464 Hence the sel_naughty flag, to identify record selectors that don't really exist.
466 In general, a field is naughty if its type mentions a type variable that
467 isn't in the result type of the constructor.
469 Note [GADT record selectors]
470 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
471 For GADTs, we require that all constructors with a common field 'f' have the same
472 result type (modulo alpha conversion). [Checked in TcTyClsDecls.checkValidTyCon]
475 T1 { f :: a } :: T [a]
476 T2 { f :: a, y :: b } :: T [a]
477 and now the selector takes that type as its argument:
478 f :: forall a. T [a] -> a
482 Note the forall'd tyvars of the selector are just the free tyvars
483 of the result type; there may be other tyvars in the constructor's
484 type (e.g. 'b' in T2).
488 -- Steps for handling "naughty" vs "non-naughty" selectors:
489 -- 1. Determine naughtiness by comparing field type vs result type
490 -- 2. Install naughty ones with selector_ty of type _|_ and fill in mzero for info
491 -- 3. If it's not naughty, do the normal plan.
493 mkRecordSelId :: TyCon -> FieldLabel -> Id
494 mkRecordSelId tycon field_label
495 -- Assumes that all fields with the same field label have the same type
496 | is_naughty = naughty_id
499 is_naughty = not (tyVarsOfType field_ty `subVarSet` res_tv_set)
500 sel_id_details = RecordSelId tycon field_label is_naughty
502 -- Escapist case here for naughty construcotrs
503 -- We give it no IdInfo, and a type of forall a.a (never looked at)
504 naughty_id = mkGlobalId sel_id_details field_label forall_a_a noCafIdInfo
505 forall_a_a = mkForAllTy alphaTyVar (mkTyVarTy alphaTyVar)
507 -- Normal case starts here
508 sel_id = mkGlobalId sel_id_details field_label selector_ty info
509 data_cons = tyConDataCons tycon
510 data_cons_w_field = filter has_field data_cons -- Can't be empty!
511 has_field con = field_label `elem` dataConFieldLabels con
513 con1 = head data_cons_w_field
514 res_tys = dataConResTys con1
515 res_tv_set = tyVarsOfTypes res_tys
516 res_tvs = varSetElems res_tv_set
517 data_ty = mkTyConApp tycon res_tys
518 field_ty = dataConFieldType con1 field_label
520 -- *Very* tiresomely, the selectors are (unnecessarily!) overloaded over
521 -- just the dictionaries in the types of the constructors that contain
522 -- the relevant field. [The Report says that pattern matching on a
523 -- constructor gives the same constraints as applying it.] Urgh.
525 -- However, not all data cons have all constraints (because of
526 -- BuildTyCl.mkDataConStupidTheta). So we need to find all the data cons
527 -- involved in the pattern match and take the union of their constraints.
528 stupid_dict_tys = mkPredTys (dataConsStupidTheta data_cons_w_field)
529 n_stupid_dicts = length stupid_dict_tys
531 (field_tyvars,pre_field_theta,field_tau) = tcSplitSigmaTy field_ty
533 field_theta = filter (not . isEqPred) pre_field_theta
534 field_dict_tys = mkPredTys field_theta
535 n_field_dict_tys = length field_dict_tys
536 -- If the field has a universally quantified type we have to
537 -- be a bit careful. Suppose we have
538 -- data R = R { op :: forall a. Foo a => a -> a }
539 -- Then we can't give op the type
540 -- op :: R -> forall a. Foo a => a -> a
541 -- because the typechecker doesn't understand foralls to the
542 -- right of an arrow. The "right" type to give it is
543 -- op :: forall a. Foo a => R -> a -> a
544 -- But then we must generate the right unfolding too:
545 -- op = /\a -> \dfoo -> \ r ->
548 -- Note that this is exactly the type we'd infer from a user defn
552 selector_ty = mkForAllTys res_tvs $ mkForAllTys field_tyvars $
553 mkFunTys stupid_dict_tys $ mkFunTys field_dict_tys $
554 mkFunTy data_ty field_tau
556 arity = 1 + n_stupid_dicts + n_field_dict_tys
558 (strict_sig, rhs_w_str) = dmdAnalTopRhs sel_rhs
559 -- Use the demand analyser to work out strictness.
560 -- With all this unpackery it's not easy!
563 `setCafInfo` caf_info
565 `setUnfoldingInfo` mkTopUnfolding rhs_w_str
566 `setAllStrictnessInfo` Just strict_sig
568 -- Allocate Ids. We do it a funny way round because field_dict_tys is
569 -- almost always empty. Also note that we use max_dict_tys
570 -- rather than n_dict_tys, because the latter gives an infinite loop:
571 -- n_dict tys depends on the_alts, which depens on arg_ids, which depends
572 -- on arity, which depends on n_dict tys. Sigh! Mega sigh!
573 stupid_dict_ids = mkTemplateLocalsNum 1 stupid_dict_tys
574 max_stupid_dicts = length (tyConStupidTheta tycon)
575 field_dict_base = max_stupid_dicts + 1
576 field_dict_ids = mkTemplateLocalsNum field_dict_base field_dict_tys
577 dict_id_base = field_dict_base + n_field_dict_tys
578 data_id = mkTemplateLocal dict_id_base data_ty
579 arg_base = dict_id_base + 1
581 the_alts :: [CoreAlt]
582 the_alts = map mk_alt data_cons_w_field -- Already sorted by data-con
583 no_default = length data_cons == length data_cons_w_field -- No default needed
585 default_alt | no_default = []
586 | otherwise = [(DEFAULT, [], error_expr)]
588 -- The default branch may have CAF refs, because it calls recSelError etc.
589 caf_info | no_default = NoCafRefs
590 | otherwise = MayHaveCafRefs
592 sel_rhs = mkLams res_tvs $ mkLams field_tyvars $
593 mkLams stupid_dict_ids $ mkLams field_dict_ids $
594 Lam data_id $ mk_result sel_body
596 -- NB: A newtype always has a vanilla DataCon; no existentials etc
597 -- res_tys will simply be the dataConUnivTyVars
598 sel_body | isNewTyCon tycon = unwrapNewTypeBody tycon res_tys (Var data_id)
599 | otherwise = Case (Var data_id) data_id field_ty (default_alt ++ the_alts)
601 mk_result poly_result = mkVarApps (mkVarApps poly_result field_tyvars) field_dict_ids
602 -- We pull the field lambdas to the top, so we need to
603 -- apply them in the body. For example:
604 -- data T = MkT { foo :: forall a. a->a }
606 -- foo :: forall a. T -> a -> a
607 -- foo = /\a. \t:T. case t of { MkT f -> f a }
610 = ASSERT2( res_ty `tcEqType` field_ty, ppr data_con $$ ppr res_ty $$ ppr field_ty )
611 mkReboxingAlt rebox_uniqs data_con (ex_tvs ++ co_tvs ++ arg_vs) rhs
613 -- get pattern binders with types appropriately instantiated
614 arg_uniqs = map mkBuiltinUnique [arg_base..]
615 (ex_tvs, co_tvs, arg_vs) = dataConOrigInstPat arg_uniqs data_con res_tys
617 rebox_base = arg_base + length ex_tvs + length co_tvs + length arg_vs
618 rebox_uniqs = map mkBuiltinUnique [rebox_base..]
620 -- data T :: *->* where T1 { fld :: Maybe b } -> T [b]
621 -- Hence T1 :: forall a b. (a=[b]) => b -> T a
622 -- fld :: forall b. T [b] -> Maybe b
623 -- fld = /\b.\(t:T[b]). case t of
624 -- T1 b' (c : [b]=[b']) (x:Maybe b')
625 -- -> x `cast` Maybe (sym (right c))
627 Succeeded refinement = gadtRefine emptyRefinement ex_tvs co_tvs
628 (co_fn, res_ty) = refineType refinement (idType the_arg_id)
629 -- Generate the refinement for b'=b,
630 -- and apply to (Maybe b'), to get (Maybe b)
633 ExprCoFn co -> Cast (Var the_arg_id) co
634 id_co -> ASSERT(isIdCoercion id_co) Var the_arg_id
636 field_vs = filter (not . isPredTy . idType) arg_vs
637 the_arg_id = assoc "mkRecordSelId:mk_alt" (field_lbls `zip` field_vs) field_label
638 field_lbls = dataConFieldLabels data_con
640 error_expr = mkRuntimeErrorApp rEC_SEL_ERROR_ID field_ty full_msg
641 full_msg = showSDoc (sep [text "No match in record selector", ppr sel_id])
643 -- unbox a product type...
644 -- we will recurse into newtypes, casting along the way, and unbox at the
645 -- first product data constructor we find. e.g.
647 -- data PairInt = PairInt Int Int
648 -- newtype S = MkS PairInt
651 -- If we have e = MkT (MkS (PairInt 0 1)) and some body expecting a list of
652 -- ids, we get (modulo int passing)
654 -- case (e `cast` CoT) `cast` CoS of
655 -- PairInt a b -> body [a,b]
657 -- The Ints passed around are just for creating fresh locals
658 unboxProduct :: Int -> CoreExpr -> Type -> (Int -> [Id] -> CoreExpr) -> CoreExpr
659 unboxProduct i arg arg_ty body
662 result = mkUnpackCase the_id arg con_args boxing_con rhs
663 (_tycon, _tycon_args, boxing_con, tys) = deepSplitProductType "unboxProduct" arg_ty
664 ([the_id], i') = mkLocals i [arg_ty]
665 (con_args, i'') = mkLocals i' tys
666 rhs = body i'' con_args
668 mkUnpackCase :: Id -> CoreExpr -> [Id] -> DataCon -> CoreExpr -> CoreExpr
669 -- (mkUnpackCase x e args Con body)
671 -- case (e `cast` ...) of bndr { Con args -> body }
673 -- the type of the bndr passed in is irrelevent
674 mkUnpackCase bndr arg unpk_args boxing_con body
675 = Case cast_arg (setIdType bndr bndr_ty) (exprType body) [(DataAlt boxing_con, unpk_args, body)]
677 (cast_arg, bndr_ty) = go (idType bndr) arg
679 | (tycon, tycon_args, _, _) <- splitProductType "mkUnpackCase" ty
680 , isNewTyCon tycon && not (isRecursiveTyCon tycon)
681 = go (newTyConInstRhs tycon tycon_args)
682 (unwrapNewTypeBody tycon tycon_args arg)
683 | otherwise = (arg, ty)
686 reboxProduct :: [Unique] -- uniques to create new local binders
687 -> Type -- type of product to box
688 -> ([Unique], -- remaining uniques
689 CoreExpr, -- boxed product
690 [Id]) -- Ids being boxed into product
693 (_tycon, _tycon_args, _pack_con, con_arg_tys) = deepSplitProductType "reboxProduct" ty
695 us' = dropList con_arg_tys us
697 arg_ids = zipWith (mkSysLocal FSLIT("rb")) us con_arg_tys
699 bind_rhs = mkProductBox arg_ids ty
702 (us', bind_rhs, arg_ids)
704 mkProductBox :: [Id] -> Type -> CoreExpr
705 mkProductBox arg_ids ty
708 (tycon, tycon_args, pack_con, _con_arg_tys) = splitProductType "mkProductBox" ty
711 | isNewTyCon tycon && not (isRecursiveTyCon tycon)
712 = wrap (mkProductBox arg_ids (newTyConInstRhs tycon tycon_args))
713 | otherwise = mkConApp pack_con (map Type tycon_args ++ map Var arg_ids)
715 wrap expr = wrapNewTypeBody tycon tycon_args expr
718 -- (mkReboxingAlt us con xs rhs) basically constructs the case
719 -- alternative (con, xs, rhs)
720 -- but it does the reboxing necessary to construct the *source*
721 -- arguments, xs, from the representation arguments ys.
723 -- data T = MkT !(Int,Int) Bool
725 -- mkReboxingAlt MkT [x,b] r
726 -- = (DataAlt MkT, [y::Int,z::Int,b], let x = (y,z) in r)
728 -- mkDataAlt should really be in DataCon, but it can't because
729 -- it manipulates CoreSyn.
732 :: [Unique] -- Uniques for the new Ids
734 -> [Var] -- Source-level args, including existential dicts
738 mkReboxingAlt us con args rhs
739 | not (any isMarkedUnboxed stricts)
740 = (DataAlt con, args, rhs)
744 (binds, args') = go args stricts us
746 (DataAlt con, args', mkLets binds rhs)
749 stricts = dataConExStricts con ++ dataConStrictMarks con
751 go [] _stricts _us = ([], [])
753 -- Type variable case
754 go (arg:args) stricts us
756 = let (binds, args') = go args stricts us
757 in (binds, arg:args')
759 -- Term variable case
760 go (arg:args) (str:stricts) us
761 | isMarkedUnboxed str
763 let (binds, unpacked_args') = go args stricts us'
764 (us', bind_rhs, unpacked_args) = reboxProduct us (idType arg)
766 (NonRec arg bind_rhs : binds, unpacked_args ++ unpacked_args')
768 = let (binds, args') = go args stricts us
769 in (binds, arg:args')
773 %************************************************************************
775 \subsection{Dictionary selectors}
777 %************************************************************************
779 Selecting a field for a dictionary. If there is just one field, then
780 there's nothing to do.
782 Dictionary selectors may get nested forall-types. Thus:
785 op :: forall b. Ord b => a -> b -> b
787 Then the top-level type for op is
789 op :: forall a. Foo a =>
793 This is unlike ordinary record selectors, which have all the for-alls
794 at the outside. When dealing with classes it's very convenient to
795 recover the original type signature from the class op selector.
798 mkDictSelId :: Name -> Class -> Id
799 mkDictSelId name clas
800 = mkGlobalId (ClassOpId clas) name sel_ty info
802 sel_ty = mkForAllTys tyvars (mkFunTy (idType dict_id) (idType the_arg_id))
803 -- We can't just say (exprType rhs), because that would give a type
805 -- for a single-op class (after all, the selector is the identity)
806 -- But it's type must expose the representation of the dictionary
807 -- to gat (say) C a -> (a -> a)
811 `setUnfoldingInfo` mkTopUnfolding rhs
812 `setAllStrictnessInfo` Just strict_sig
814 -- We no longer use 'must-inline' on record selectors. They'll
815 -- inline like crazy if they scrutinise a constructor
817 -- The strictness signature is of the form U(AAAVAAAA) -> T
818 -- where the V depends on which item we are selecting
819 -- It's worth giving one, so that absence info etc is generated
820 -- even if the selector isn't inlined
821 strict_sig = mkStrictSig (mkTopDmdType [arg_dmd] TopRes)
822 arg_dmd | isNewTyCon tycon = evalDmd
823 | otherwise = Eval (Prod [ if the_arg_id == id then evalDmd else Abs
826 tycon = classTyCon clas
827 [data_con] = tyConDataCons tycon
828 tyvars = dataConUnivTyVars data_con
829 arg_tys = ASSERT( isVanillaDataCon data_con ) dataConRepArgTys data_con
830 the_arg_id = assoc "MkId.mkDictSelId" (map idName (classSelIds clas) `zip` arg_ids) name
832 pred = mkClassPred clas (mkTyVarTys tyvars)
833 (dict_id:arg_ids) = mkTemplateLocals (mkPredTy pred : arg_tys)
835 rhs = mkLams tyvars (Lam dict_id rhs_body)
836 rhs_body | isNewTyCon tycon = unwrapNewTypeBody tycon (map mkTyVarTy tyvars) (Var dict_id)
837 | otherwise = Case (Var dict_id) dict_id (idType the_arg_id)
838 [(DataAlt data_con, arg_ids, Var the_arg_id)]
840 wrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
841 -- The wrapper for the data constructor for a newtype looks like this:
842 -- newtype T a = MkT (a,Int)
843 -- MkT :: forall a. (a,Int) -> T a
844 -- MkT = /\a. \(x:(a,Int)). x `cast` sym (CoT a)
845 -- where CoT is the coercion TyCon assoicated with the newtype
847 -- The call (wrapNewTypeBody T [a] e) returns the
848 -- body of the wrapper, namely
849 -- e `cast` (CoT [a])
851 -- If a coercion constructor is prodivided in the newtype, then we use
852 -- it, otherwise the wrap/unwrap are both no-ops
854 -- If the we are dealing with a newtype instance, we have a second coercion
855 -- identifying the family instance with the constructor of the newtype
856 -- instance. This coercion is applied in any case (ie, composed with the
857 -- coercion constructor of the newtype or applied by itself).
859 wrapNewTypeBody tycon args result_expr
860 = wrapFamInstBody tycon args inner
863 | Just co_con <- newTyConCo tycon
864 = mkCoerce (mkSymCoercion (mkTyConApp co_con args)) result_expr
868 -- When unwrapping, we do *not* apply any family coercion, because this will
869 -- be done via a CoPat by the type checker. We have to do it this way as
870 -- computing the right type arguments for the coercion requires more than just
871 -- a spliting operation (cf, TcPat.tcConPat).
873 unwrapNewTypeBody :: TyCon -> [Type] -> CoreExpr -> CoreExpr
874 unwrapNewTypeBody tycon args result_expr
875 | Just co_con <- newTyConCo tycon
876 = mkCoerce (mkTyConApp co_con args) result_expr
884 %************************************************************************
886 \subsection{Primitive operations
888 %************************************************************************
891 mkPrimOpId :: PrimOp -> Id
895 (tyvars,arg_tys,res_ty, arity, strict_sig) = primOpSig prim_op
896 ty = mkForAllTys tyvars (mkFunTys arg_tys res_ty)
897 name = mkWiredInName gHC_PRIM (primOpOcc prim_op)
898 (mkPrimOpIdUnique (primOpTag prim_op))
899 Nothing (AnId id) UserSyntax
900 id = mkGlobalId (PrimOpId prim_op) name ty info
903 `setSpecInfo` mkSpecInfo (primOpRules prim_op name)
905 `setAllStrictnessInfo` Just strict_sig
907 -- For each ccall we manufacture a separate CCallOpId, giving it
908 -- a fresh unique, a type that is correct for this particular ccall,
909 -- and a CCall structure that gives the correct details about calling
912 -- The *name* of this Id is a local name whose OccName gives the full
913 -- details of the ccall, type and all. This means that the interface
914 -- file reader can reconstruct a suitable Id
916 mkFCallId :: Unique -> ForeignCall -> Type -> Id
917 mkFCallId uniq fcall ty
918 = ASSERT( isEmptyVarSet (tyVarsOfType ty) )
919 -- A CCallOpId should have no free type variables;
920 -- when doing substitutions won't substitute over it
921 mkGlobalId (FCallId fcall) name ty info
923 occ_str = showSDoc (braces (ppr fcall <+> ppr ty))
924 -- The "occurrence name" of a ccall is the full info about the
925 -- ccall; it is encoded, but may have embedded spaces etc!
927 name = mkFCallName uniq occ_str
931 `setAllStrictnessInfo` Just strict_sig
933 (_, tau) = tcSplitForAllTys ty
934 (arg_tys, _) = tcSplitFunTys tau
935 arity = length arg_tys
936 strict_sig = mkStrictSig (mkTopDmdType (replicate arity evalDmd) TopRes)
940 %************************************************************************
942 \subsection{DictFuns and default methods}
944 %************************************************************************
946 Important notes about dict funs and default methods
947 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
948 Dict funs and default methods are *not* ImplicitIds. Their definition
949 involves user-written code, so we can't figure out their strictness etc
950 based on fixed info, as we can for constructors and record selectors (say).
952 We build them as LocalIds, but with External Names. This ensures that
953 they are taken to account by free-variable finding and dependency
954 analysis (e.g. CoreFVs.exprFreeVars).
956 Why shouldn't they be bound as GlobalIds? Because, in particular, if
957 they are globals, the specialiser floats dict uses above their defns,
958 which prevents good simplifications happening. Also the strictness
959 analyser treats a occurrence of a GlobalId as imported and assumes it
960 contains strictness in its IdInfo, which isn't true if the thing is
961 bound in the same module as the occurrence.
963 It's OK for dfuns to be LocalIds, because we form the instance-env to
964 pass on to the next module (md_insts) in CoreTidy, afer tidying
965 and globalising the top-level Ids.
967 BUT make sure they are *exported* LocalIds (mkExportedLocalId) so
968 that they aren't discarded by the occurrence analyser.
971 mkDefaultMethodId dm_name ty = mkExportedLocalId dm_name ty
973 mkDictFunId :: Name -- Name to use for the dict fun;
980 mkDictFunId dfun_name inst_tyvars dfun_theta clas inst_tys
981 = mkExportedLocalId dfun_name dfun_ty
983 dfun_ty = mkSigmaTy inst_tyvars dfun_theta (mkDictTy clas inst_tys)
985 {- 1 dec 99: disable the Mark Jones optimisation for the sake
986 of compatibility with Hugs.
987 See `types/InstEnv' for a discussion related to this.
989 (class_tyvars, sc_theta, _, _) = classBigSig clas
990 not_const (clas, tys) = not (isEmptyVarSet (tyVarsOfTypes tys))
991 sc_theta' = substClasses (zipTopTvSubst class_tyvars inst_tys) sc_theta
992 dfun_theta = case inst_decl_theta of
993 [] -> [] -- If inst_decl_theta is empty, then we don't
994 -- want to have any dict arguments, so that we can
995 -- expose the constant methods.
997 other -> nub (inst_decl_theta ++ filter not_const sc_theta')
998 -- Otherwise we pass the superclass dictionaries to
999 -- the dictionary function; the Mark Jones optimisation.
1001 -- NOTE the "nub". I got caught by this one:
1002 -- class Monad m => MonadT t m where ...
1003 -- instance Monad m => MonadT (EnvT env) m where ...
1004 -- Here, the inst_decl_theta has (Monad m); but so
1005 -- does the sc_theta'!
1007 -- NOTE the "not_const". I got caught by this one too:
1008 -- class Foo a => Baz a b where ...
1009 -- instance Wob b => Baz T b where..
1010 -- Now sc_theta' has Foo T
1015 %************************************************************************
1017 \subsection{Un-definable}
1019 %************************************************************************
1021 These Ids can't be defined in Haskell. They could be defined in
1022 unfoldings in the wired-in GHC.Prim interface file, but we'd have to
1023 ensure that they were definitely, definitely inlined, because there is
1024 no curried identifier for them. That's what mkCompulsoryUnfolding
1025 does. If we had a way to get a compulsory unfolding from an interface
1026 file, we could do that, but we don't right now.
1028 unsafeCoerce# isn't so much a PrimOp as a phantom identifier, that
1029 just gets expanded into a type coercion wherever it occurs. Hence we
1030 add it as a built-in Id with an unfolding here.
1032 The type variables we use here are "open" type variables: this means
1033 they can unify with both unlifted and lifted types. Hence we provide
1034 another gun with which to shoot yourself in the foot.
1037 mkWiredInIdName mod fs uniq id
1038 = mkWiredInName mod (mkOccNameFS varName fs) uniq Nothing (AnId id) UserSyntax
1040 unsafeCoerceName = mkWiredInIdName gHC_PRIM FSLIT("unsafeCoerce#") unsafeCoerceIdKey unsafeCoerceId
1041 nullAddrName = mkWiredInIdName gHC_PRIM FSLIT("nullAddr#") nullAddrIdKey nullAddrId
1042 seqName = mkWiredInIdName gHC_PRIM FSLIT("seq") seqIdKey seqId
1043 realWorldName = mkWiredInIdName gHC_PRIM FSLIT("realWorld#") realWorldPrimIdKey realWorldPrimId
1044 lazyIdName = mkWiredInIdName gHC_BASE FSLIT("lazy") lazyIdKey lazyId
1046 errorName = mkWiredInIdName gHC_ERR FSLIT("error") errorIdKey eRROR_ID
1047 recSelErrorName = mkWiredInIdName gHC_ERR FSLIT("recSelError") recSelErrorIdKey rEC_SEL_ERROR_ID
1048 runtimeErrorName = mkWiredInIdName gHC_ERR FSLIT("runtimeError") runtimeErrorIdKey rUNTIME_ERROR_ID
1049 irrefutPatErrorName = mkWiredInIdName gHC_ERR FSLIT("irrefutPatError") irrefutPatErrorIdKey iRREFUT_PAT_ERROR_ID
1050 recConErrorName = mkWiredInIdName gHC_ERR FSLIT("recConError") recConErrorIdKey rEC_CON_ERROR_ID
1051 patErrorName = mkWiredInIdName gHC_ERR FSLIT("patError") patErrorIdKey pAT_ERROR_ID
1052 noMethodBindingErrorName = mkWiredInIdName gHC_ERR FSLIT("noMethodBindingError")
1053 noMethodBindingErrorIdKey nO_METHOD_BINDING_ERROR_ID
1054 nonExhaustiveGuardsErrorName
1055 = mkWiredInIdName gHC_ERR FSLIT("nonExhaustiveGuardsError")
1056 nonExhaustiveGuardsErrorIdKey nON_EXHAUSTIVE_GUARDS_ERROR_ID
1060 -- unsafeCoerce# :: forall a b. a -> b
1062 = pcMiscPrelId unsafeCoerceName ty info
1064 info = noCafIdInfo `setUnfoldingInfo` mkCompulsoryUnfolding rhs
1067 ty = mkForAllTys [openAlphaTyVar,openBetaTyVar]
1068 (mkFunTy openAlphaTy openBetaTy)
1069 [x] = mkTemplateLocals [openAlphaTy]
1070 rhs = mkLams [openAlphaTyVar,openBetaTyVar,x] $
1071 -- Note (Coerce openBetaTy openAlphaTy) (Var x)
1072 Cast (Var x) (mkUnsafeCoercion openAlphaTy openBetaTy)
1074 -- nullAddr# :: Addr#
1075 -- The reason is is here is because we don't provide
1076 -- a way to write this literal in Haskell.
1078 = pcMiscPrelId nullAddrName addrPrimTy info
1080 info = noCafIdInfo `setUnfoldingInfo`
1081 mkCompulsoryUnfolding (Lit nullAddrLit)
1084 = pcMiscPrelId seqName ty info
1086 info = noCafIdInfo `setUnfoldingInfo` mkCompulsoryUnfolding rhs
1089 ty = mkForAllTys [alphaTyVar,openBetaTyVar]
1090 (mkFunTy alphaTy (mkFunTy openBetaTy openBetaTy))
1091 [x,y] = mkTemplateLocals [alphaTy, openBetaTy]
1092 rhs = mkLams [alphaTyVar,openBetaTyVar,x,y] (Case (Var x) x openBetaTy [(DEFAULT, [], Var y)])
1094 -- lazy :: forall a?. a? -> a? (i.e. works for unboxed types too)
1095 -- Used to lazify pseq: pseq a b = a `seq` lazy b
1097 -- Also, no strictness: by being a built-in Id, all the info about lazyId comes from here,
1098 -- not from GHC.Base.hi. This is important, because the strictness
1099 -- analyser will spot it as strict!
1101 -- Also no unfolding in lazyId: it gets "inlined" by a HACK in the worker/wrapper pass
1102 -- (see WorkWrap.wwExpr)
1103 -- We could use inline phases to do this, but that would be vulnerable to changes in
1104 -- phase numbering....we must inline precisely after strictness analysis.
1106 = pcMiscPrelId lazyIdName ty info
1109 ty = mkForAllTys [alphaTyVar] (mkFunTy alphaTy alphaTy)
1111 lazyIdUnfolding :: CoreExpr -- Used to expand 'lazyId' after strictness anal
1112 lazyIdUnfolding = mkLams [openAlphaTyVar,x] (Var x)
1114 [x] = mkTemplateLocals [openAlphaTy]
1117 @realWorld#@ used to be a magic literal, \tr{void#}. If things get
1118 nasty as-is, change it back to a literal (@Literal@).
1120 voidArgId is a Local Id used simply as an argument in functions
1121 where we just want an arg to avoid having a thunk of unlifted type.
1123 x = \ void :: State# RealWorld -> (# p, q #)
1125 This comes up in strictness analysis
1128 realWorldPrimId -- :: State# RealWorld
1129 = pcMiscPrelId realWorldName realWorldStatePrimTy
1130 (noCafIdInfo `setUnfoldingInfo` evaldUnfolding)
1131 -- The evaldUnfolding makes it look that realWorld# is evaluated
1132 -- which in turn makes Simplify.interestingArg return True,
1133 -- which in turn makes INLINE things applied to realWorld# likely
1136 voidArgId -- :: State# RealWorld
1137 = mkSysLocal FSLIT("void") voidArgIdKey realWorldStatePrimTy
1141 %************************************************************************
1143 \subsection[PrelVals-error-related]{@error@ and friends; @trace@}
1145 %************************************************************************
1147 GHC randomly injects these into the code.
1149 @patError@ is just a version of @error@ for pattern-matching
1150 failures. It knows various ``codes'' which expand to longer
1151 strings---this saves space!
1153 @absentErr@ is a thing we put in for ``absent'' arguments. They jolly
1154 well shouldn't be yanked on, but if one is, then you will get a
1155 friendly message from @absentErr@ (rather than a totally random
1158 @parError@ is a special version of @error@ which the compiler does
1159 not know to be a bottoming Id. It is used in the @_par_@ and @_seq_@
1160 templates, but we don't ever expect to generate code for it.
1164 :: Id -- Should be of type (forall a. Addr# -> a)
1165 -- where Addr# points to a UTF8 encoded string
1166 -> Type -- The type to instantiate 'a'
1167 -> String -- The string to print
1170 mkRuntimeErrorApp err_id res_ty err_msg
1171 = mkApps (Var err_id) [Type res_ty, err_string]
1173 err_string = Lit (mkStringLit err_msg)
1175 rEC_SEL_ERROR_ID = mkRuntimeErrorId recSelErrorName
1176 rUNTIME_ERROR_ID = mkRuntimeErrorId runtimeErrorName
1177 iRREFUT_PAT_ERROR_ID = mkRuntimeErrorId irrefutPatErrorName
1178 rEC_CON_ERROR_ID = mkRuntimeErrorId recConErrorName
1179 pAT_ERROR_ID = mkRuntimeErrorId patErrorName
1180 nO_METHOD_BINDING_ERROR_ID = mkRuntimeErrorId noMethodBindingErrorName
1181 nON_EXHAUSTIVE_GUARDS_ERROR_ID = mkRuntimeErrorId nonExhaustiveGuardsErrorName
1183 -- The runtime error Ids take a UTF8-encoded string as argument
1184 mkRuntimeErrorId name = pc_bottoming_Id name runtimeErrorTy
1185 runtimeErrorTy = mkSigmaTy [openAlphaTyVar] [] (mkFunTy addrPrimTy openAlphaTy)
1189 eRROR_ID = pc_bottoming_Id errorName errorTy
1192 errorTy = mkSigmaTy [openAlphaTyVar] [] (mkFunTys [mkListTy charTy] openAlphaTy)
1193 -- Notice the openAlphaTyVar. It says that "error" can be applied
1194 -- to unboxed as well as boxed types. This is OK because it never
1195 -- returns, so the return type is irrelevant.
1199 %************************************************************************
1201 \subsection{Utilities}
1203 %************************************************************************
1206 pcMiscPrelId :: Name -> Type -> IdInfo -> Id
1207 pcMiscPrelId name ty info
1208 = mkVanillaGlobal name ty info
1209 -- We lie and say the thing is imported; otherwise, we get into
1210 -- a mess with dependency analysis; e.g., core2stg may heave in
1211 -- random calls to GHCbase.unpackPS__. If GHCbase is the module
1212 -- being compiled, then it's just a matter of luck if the definition
1213 -- will be in "the right place" to be in scope.
1215 pc_bottoming_Id name ty
1216 = pcMiscPrelId name ty bottoming_info
1218 bottoming_info = vanillaIdInfo `setAllStrictnessInfo` Just strict_sig
1219 -- Do *not* mark them as NoCafRefs, because they can indeed have
1220 -- CAF refs. For example, pAT_ERROR_ID calls GHC.Err.untangle,
1221 -- which has some CAFs
1222 -- In due course we may arrange that these error-y things are
1223 -- regarded by the GC as permanently live, in which case we
1224 -- can give them NoCaf info. As it is, any function that calls
1225 -- any pc_bottoming_Id will itself have CafRefs, which bloats
1228 strict_sig = mkStrictSig (mkTopDmdType [evalDmd] BotRes)
1229 -- These "bottom" out, no matter what their arguments
1231 (openAlphaTyVar:openBetaTyVar:_) = openAlphaTyVars
1232 openAlphaTy = mkTyVarTy openAlphaTyVar
1233 openBetaTy = mkTyVarTy openBetaTyVar