2 % (c) The GRASP/AQUA Project, Glasgow University, 1998
4 \section[DataCon]{@DataCon@: Data Constructors}
8 DataCon, DataConIds(..),
11 dataConRepType, dataConSig, dataConFullSig,
12 dataConName, dataConTag, dataConTyCon, dataConUserType,
13 dataConUnivTyVars, dataConExTyVars, dataConAllTyVars, dataConResTys,
14 dataConEqSpec, eqSpecPreds, dataConTheta, dataConStupidTheta,
15 dataConInstArgTys, dataConOrigArgTys,
16 dataConInstOrigArgTys, dataConRepArgTys,
17 dataConFieldLabels, dataConFieldType,
18 dataConStrictMarks, dataConExStricts,
19 dataConSourceArity, dataConRepArity,
21 dataConWorkId, dataConWrapId, dataConWrapId_maybe, dataConImplicitIds,
23 isNullarySrcDataCon, isNullaryRepDataCon, isTupleCon, isUnboxedTupleCon,
24 isVanillaDataCon, classDataCon,
26 splitProductType_maybe, splitProductType, deepSplitProductType,
27 deepSplitProductType_maybe
30 #include "HsVersions.h"
32 import Type ( Type, ThetaType,
33 substTyWith, substTyVar, mkTopTvSubst,
34 mkForAllTys, mkFunTys, mkTyConApp, mkTyVarTy, mkTyVarTys,
35 splitTyConApp_maybe, newTyConInstRhs,
36 mkPredTys, isStrictPred, pprType, mkPredTy
38 import Coercion ( isEqPred, mkEqPred )
39 import TyCon ( TyCon, FieldLabel, tyConDataCons,
40 isProductTyCon, isTupleTyCon, isUnboxedTupleTyCon,
41 isNewTyCon, isRecursiveTyCon )
42 import Class ( Class, classTyCon )
43 import Name ( Name, NamedThing(..), nameUnique, mkSysTvName, mkSystemName )
44 + import Var ( TyVar, CoVar, Id, mkTyVar, tyVarKind, setVarUnique,
46 import BasicTypes ( Arity, StrictnessMark(..) )
48 import Unique ( Unique, Uniquable(..) )
49 import ListSetOps ( assoc, minusList )
50 import Util ( zipEqual, zipWithEqual )
51 import List ( partition )
52 import Maybes ( expectJust )
57 Data constructor representation
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59 Consider the following Haskell data type declaration
61 data T = T !Int ![Int]
63 Using the strictness annotations, GHC will represent this as
67 That is, the Int has been unboxed. Furthermore, the Haskell source construction
77 That is, the first argument is unboxed, and the second is evaluated. Finally,
78 pattern matching is translated too:
80 case e of { T a b -> ... }
84 case e of { T a' b -> let a = I# a' in ... }
86 To keep ourselves sane, we name the different versions of the data constructor
87 differently, as follows.
90 Note [Data Constructor Naming]
91 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 Each data constructor C has two, and possibly three, Names associated with it:
94 OccName Name space Used for
95 ---------------------------------------------------------------------------
96 * The "source data con" C DataName The DataCon itself
97 * The "real data con" C VarName Its worker Id
98 * The "wrapper data con" $WC VarName Wrapper Id (optional)
100 Each of these three has a distinct Unique. The "source data con" name
101 appears in the output of the renamer, and names the Haskell-source
102 data constructor. The type checker translates it into either the wrapper Id
103 (if it exists) or worker Id (otherwise).
105 The data con has one or two Ids associated with it:
107 The "worker Id", is the actual data constructor.
108 Its type may be different to the Haskell source constructor
110 - useless dict args are dropped
111 - strict args may be flattened
112 The worker is very like a primop, in that it has no binding.
116 The "wrapper Id", $WC, whose type is exactly what it looks like
117 in the source program. It is an ordinary function,
118 and it gets a top-level binding like any other function.
120 The wrapper Id isn't generated for a data type if the worker
121 and wrapper are identical.
125 A note about the stupid context
126 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127 Data types can have a context:
129 data (Eq a, Ord b) => T a b = T1 a b | T2 a
131 and that makes the constructors have a context too
132 (notice that T2's context is "thinned"):
134 T1 :: (Eq a, Ord b) => a -> b -> T a b
135 T2 :: (Eq a) => a -> T a b
137 Furthermore, this context pops up when pattern matching
138 (though GHC hasn't implemented this, but it is in H98, and
139 I've fixed GHC so that it now does):
143 f :: Eq a => T a b -> a
145 I say the context is "stupid" because the dictionaries passed
146 are immediately discarded -- they do nothing and have no benefit.
147 It's a flaw in the language.
149 Up to now [March 2002] I have put this stupid context into the
150 type of the "wrapper" constructors functions, T1 and T2, but
151 that turned out to be jolly inconvenient for generics, and
152 record update, and other functions that build values of type T
153 (because they don't have suitable dictionaries available).
155 So now I've taken the stupid context out. I simply deal with
156 it separately in the type checker on occurrences of a
157 constructor, either in an expression or in a pattern.
159 [May 2003: actually I think this decision could evasily be
160 reversed now, and probably should be. Generics could be
161 disabled for types with a stupid context; record updates now
162 (H98) needs the context too; etc. It's an unforced change, so
163 I'm leaving it for now --- but it does seem odd that the
164 wrapper doesn't include the stupid context.]
166 [July 04] With the advent of generalised data types, it's less obvious
167 what the "stupid context" is. Consider
168 C :: forall a. Ord a => a -> a -> T (Foo a)
169 Does the C constructor in Core contain the Ord dictionary? Yes, it must:
174 C a (d:Ord a) (p:a) (q:a) -> compare d p q
176 Note that (Foo a) might not be an instance of Ord.
178 %************************************************************************
180 \subsection{Data constructors}
182 %************************************************************************
187 dcName :: Name, -- This is the name of the *source data con*
188 -- (see "Note [Data Constructor Naming]" above)
189 dcUnique :: Unique, -- Cached from Name
194 -- *** As declared by the user
196 -- MkT :: forall x y. (Ord x) => x -> y -> T (x,y)
198 -- *** As represented internally
200 -- MkT :: forall a. forall x y. (a:=:(x,y), Ord x) => x -> y -> T a
202 -- The next six fields express the type of the constructor, in pieces
205 -- dcUnivTyVars = [a]
206 -- dcExTyVars = [x,y]
207 -- dcEqSpec = [a:=:(x,y)]
209 -- dcOrigArgTys = [a,List b]
212 dcVanilla :: Bool, -- True <=> This is a vanilla Haskell 98 data constructor
213 -- Its type is of form
214 -- forall a1..an . t1 -> ... tm -> T a1..an
215 -- No existentials, no coercions, nothing.
216 -- That is: dcExTyVars = dcEqSpec = dcTheta = []
217 -- NB 1: newtypes always have a vanilla data con
218 -- NB 2: a vanilla constructor can still be declared in GADT-style
219 -- syntax, provided its type looks like the above.
220 -- The declaration format is held in the TyCon (algTcGadtSyntax)
222 dcUnivTyVars :: [TyVar], -- Universally-quantified type vars
223 dcExTyVars :: [TyVar], -- Existentially-quantified type vars
224 -- In general, the dcUnivTyVars are NOT NECESSARILY THE SAME AS THE TYVARS
225 -- FOR THE PARENT TyCon. With GADTs the data con might not even have
226 -- the same number of type variables.
227 -- [This is a change (Oct05): previously, vanilla datacons guaranteed to
228 -- have the same type variables as their parent TyCon, but that seems ugly.]
230 dcEqSpec :: [(TyVar,Type)], -- Equalities derived from the result type,
231 -- *as written by the programmer*
232 -- This field allows us to move conveniently between the two ways
233 -- of representing a GADT constructor's type:
234 -- MkT :: forall a b. (a :=: [b]) => b -> T a
235 -- MkT :: forall b. b -> T [b]
236 -- Each equality is of the form (a :=: ty), where 'a' is one of
237 -- the universally quantified type variables
239 dcTheta :: ThetaType, -- The context of the constructor
240 -- In GADT form, this is *exactly* what the programmer writes, even if
241 -- the context constrains only universally quantified variables
242 -- MkT :: forall a. Eq a => a -> T a
243 -- It may contain user-written equality predicates too
245 dcStupidTheta :: ThetaType, -- The context of the data type declaration
246 -- data Eq a => T a = ...
247 -- or, rather, a "thinned" version thereof
248 -- "Thinned", because the Report says
249 -- to eliminate any constraints that don't mention
250 -- tyvars free in the arg types for this constructor
252 -- INVARIANT: the free tyvars of dcStupidTheta are a subset of dcUnivTyVars
253 -- Reason: dcStupidTeta is gotten by thinning the stupid theta from the tycon
255 -- "Stupid", because the dictionaries aren't used for anything.
256 -- Indeed, [as of March 02] they are no longer in the type of
257 -- the wrapper Id, because that makes it harder to use the wrap-id
258 -- to rebuild values after record selection or in generics.
260 dcOrigArgTys :: [Type], -- Original argument types
261 -- (before unboxing and flattening of strict fields)
263 -- Result type of constructor is T t1..tn
264 dcTyCon :: TyCon, -- Result tycon, T
266 -- Now the strictness annotations and field labels of the constructor
267 dcStrictMarks :: [StrictnessMark],
268 -- Strictness annotations as decided by the compiler.
269 -- Does *not* include the existential dictionaries
270 -- length = dataConSourceArity dataCon
272 dcFields :: [FieldLabel],
273 -- Field labels for this constructor, in the
274 -- same order as the argument types;
275 -- length = 0 (if not a record) or dataConSourceArity.
277 -- Constructor representation
278 dcRepArgTys :: [Type], -- Final, representation argument types,
279 -- after unboxing and flattening,
280 -- and *including* existential dictionaries
282 dcRepStrictness :: [StrictnessMark], -- One for each *representation* argument
284 dcRepType :: Type, -- Type of the constructor
285 -- forall a x y. (a:=:(x,y), Ord x) => x -> y -> MkT a
286 -- (this is *not* of the constructor wrapper Id:
287 -- see Note [Data con representation] below)
288 -- Notice that the existential type parameters come *second*.
289 -- Reason: in a case expression we may find:
290 -- case (e :: T t) of { MkT b (d:Ord b) (x:t) (xs:[b]) -> ... }
291 -- It's convenient to apply the rep-type of MkT to 't', to get
292 -- forall b. Ord b => ...
293 -- and use that to check the pattern. Mind you, this is really only
297 -- Finally, the curried worker function that corresponds to the constructor
298 -- It doesn't have an unfolding; the code generator saturates these Ids
299 -- and allocates a real constructor when it finds one.
301 -- An entirely separate wrapper function is built in TcTyDecls
304 dcInfix :: Bool -- True <=> declared infix
305 -- Used for Template Haskell and 'deriving' only
306 -- The actual fixity is stored elsewhere
310 = DCIds (Maybe Id) Id -- Algebraic data types always have a worker, and
311 -- may or may not have a wrapper, depending on whether
312 -- the wrapper does anything. Newtypes just have a worker
314 -- _Neither_ the worker _nor_ the wrapper take the dcStupidTheta dicts as arguments
316 -- The wrapper takes dcOrigArgTys as its arguments
317 -- The worker takes dcRepArgTys as its arguments
318 -- If the worker is absent, dcRepArgTys is the same as dcOrigArgTys
320 -- The 'Nothing' case of DCIds is important
321 -- Not only is this efficient,
322 -- but it also ensures that the wrapper is replaced
323 -- by the worker (becuase it *is* the wroker)
324 -- even when there are no args. E.g. in
326 -- the (:) *is* the worker.
327 -- This is really important in rule matching,
328 -- (We could match on the wrappers,
329 -- but that makes it less likely that rules will match
330 -- when we bring bits of unfoldings together.)
335 fIRST_TAG = 1 -- Tags allocated from here for real constructors
338 Note [Data con representation]
339 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340 The dcRepType field contains the type of the representation of a contructor
341 This may differ from the type of the contructor *Id* (built
342 by MkId.mkDataConId) for two reasons:
343 a) the constructor Id may be overloaded, but the dictionary isn't stored
344 e.g. data Eq a => T a = MkT a a
346 b) the constructor may store an unboxed version of a strict field.
348 Here's an example illustrating both:
349 data Ord a => T a = MkT Int! a
351 T :: Ord a => Int -> a -> T a
353 Trep :: Int# -> a -> T a
354 Actually, the unboxed part isn't implemented yet!
357 %************************************************************************
359 \subsection{Instances}
361 %************************************************************************
364 instance Eq DataCon where
365 a == b = getUnique a == getUnique b
366 a /= b = getUnique a /= getUnique b
368 instance Ord DataCon where
369 a <= b = getUnique a <= getUnique b
370 a < b = getUnique a < getUnique b
371 a >= b = getUnique a >= getUnique b
372 a > b = getUnique a > getUnique b
373 compare a b = getUnique a `compare` getUnique b
375 instance Uniquable DataCon where
378 instance NamedThing DataCon where
381 instance Outputable DataCon where
382 ppr con = ppr (dataConName con)
384 instance Show DataCon where
385 showsPrec p con = showsPrecSDoc p (ppr con)
389 %************************************************************************
391 \subsection{Construction}
393 %************************************************************************
397 -> Bool -- Declared infix
398 -> [StrictnessMark] -> [FieldLabel]
399 -> [TyVar] -> [TyVar]
400 -> [(TyVar,Type)] -> ThetaType
402 -> ThetaType -> DataConIds
404 -- Can get the tag from the TyCon
406 mkDataCon name declared_infix
407 arg_stricts -- Must match orig_arg_tys 1-1
413 = ASSERT( not (any isEqPred theta) )
414 -- We don't currently allow any equality predicates on
415 -- a data constructor (apart from the GADT ones in eq_spec)
418 is_vanilla = null ex_tvs && null eq_spec && null theta
419 con = ASSERT( is_vanilla || not (isNewTyCon tycon) )
420 -- Invariant: newtypes have a vanilla data-con
421 MkData {dcName = name, dcUnique = nameUnique name,
422 dcVanilla = is_vanilla, dcInfix = declared_infix,
423 dcUnivTyVars = univ_tvs, dcExTyVars = ex_tvs,
425 dcStupidTheta = stupid_theta, dcTheta = theta,
426 dcOrigArgTys = orig_arg_tys, dcTyCon = tycon,
427 dcRepArgTys = rep_arg_tys,
428 dcStrictMarks = arg_stricts, dcRepStrictness = rep_arg_stricts,
429 dcFields = fields, dcTag = tag, dcRepType = ty,
432 -- Strictness marks for source-args
433 -- *after unboxing choices*,
434 -- but *including existential dictionaries*
436 -- The 'arg_stricts' passed to mkDataCon are simply those for the
437 -- source-language arguments. We add extra ones for the
438 -- dictionary arguments right here.
439 dict_tys = mkPredTys theta
440 real_arg_tys = dict_tys ++ orig_arg_tys
441 real_stricts = map mk_dict_strict_mark theta ++ arg_stricts
443 -- Representation arguments and demands
444 -- To do: eliminate duplication with MkId
445 (rep_arg_stricts, rep_arg_tys) = computeRep real_stricts real_arg_tys
447 tag = assoc "mkDataCon" (tyConDataCons tycon `zip` [fIRST_TAG..]) con
448 ty = mkForAllTys univ_tvs $ mkForAllTys ex_tvs $
449 mkFunTys (mkPredTys (eqSpecPreds eq_spec)) $
450 -- NB: the dict args are already in rep_arg_tys
451 -- because they might be flattened..
452 -- but the equality predicates are not
453 mkFunTys rep_arg_tys $
454 mkTyConApp tycon (mkTyVarTys univ_tvs)
456 eqSpecPreds :: [(TyVar,Type)] -> ThetaType
457 eqSpecPreds spec = [ mkEqPred (mkTyVarTy tv, ty) | (tv,ty) <- spec ]
459 mk_dict_strict_mark pred | isStrictPred pred = MarkedStrict
460 | otherwise = NotMarkedStrict
464 dataConName :: DataCon -> Name
467 dataConTag :: DataCon -> ConTag
470 dataConTyCon :: DataCon -> TyCon
471 dataConTyCon = dcTyCon
473 dataConRepType :: DataCon -> Type
474 dataConRepType = dcRepType
476 dataConIsInfix :: DataCon -> Bool
477 dataConIsInfix = dcInfix
479 dataConUnivTyVars :: DataCon -> [TyVar]
480 dataConUnivTyVars = dcUnivTyVars
482 dataConExTyVars :: DataCon -> [TyVar]
483 dataConExTyVars = dcExTyVars
485 dataConAllTyVars :: DataCon -> [TyVar]
486 dataConAllTyVars (MkData { dcUnivTyVars = univ_tvs, dcExTyVars = ex_tvs })
489 dataConEqSpec :: DataCon -> [(TyVar,Type)]
490 dataConEqSpec = dcEqSpec
492 dataConTheta :: DataCon -> ThetaType
493 dataConTheta = dcTheta
495 dataConWorkId :: DataCon -> Id
496 dataConWorkId dc = case dcIds dc of
497 DCIds _ wrk_id -> wrk_id
499 dataConWrapId_maybe :: DataCon -> Maybe Id
500 -- Returns Nothing if there is no wrapper for an algebraic data con
501 -- and also for a newtype (whose constructor is inlined compulsorily)
502 dataConWrapId_maybe dc = case dcIds dc of
503 DCIds mb_wrap _ -> mb_wrap
505 dataConWrapId :: DataCon -> Id
506 -- Returns an Id which looks like the Haskell-source constructor
507 dataConWrapId dc = case dcIds dc of
508 DCIds (Just wrap) _ -> wrap
509 DCIds Nothing wrk -> wrk -- worker=wrapper
511 dataConImplicitIds :: DataCon -> [Id]
512 dataConImplicitIds dc = case dcIds dc of
513 DCIds (Just wrap) work -> [wrap,work]
514 DCIds Nothing work -> [work]
516 dataConFieldLabels :: DataCon -> [FieldLabel]
517 dataConFieldLabels = dcFields
519 dataConFieldType :: DataCon -> FieldLabel -> Type
520 dataConFieldType con label = expectJust "unexpected label" $
521 lookup label (dcFields con `zip` dcOrigArgTys con)
523 dataConStrictMarks :: DataCon -> [StrictnessMark]
524 dataConStrictMarks = dcStrictMarks
526 dataConExStricts :: DataCon -> [StrictnessMark]
527 -- Strictness of *existential* arguments only
528 -- Usually empty, so we don't bother to cache this
529 dataConExStricts dc = map mk_dict_strict_mark (dcTheta dc)
531 dataConSourceArity :: DataCon -> Arity
532 -- Source-level arity of the data constructor
533 dataConSourceArity dc = length (dcOrigArgTys dc)
535 -- dataConRepArity gives the number of actual fields in the
536 -- {\em representation} of the data constructor. This may be more than appear
537 -- in the source code; the extra ones are the existentially quantified
539 dataConRepArity (MkData {dcRepArgTys = arg_tys}) = length arg_tys
541 isNullarySrcDataCon, isNullaryRepDataCon :: DataCon -> Bool
542 isNullarySrcDataCon dc = null (dcOrigArgTys dc)
543 isNullaryRepDataCon dc = null (dcRepArgTys dc)
545 dataConRepStrictness :: DataCon -> [StrictnessMark]
546 -- Give the demands on the arguments of a
547 -- Core constructor application (Con dc args)
548 dataConRepStrictness dc = dcRepStrictness dc
550 dataConSig :: DataCon -> ([TyVar], ThetaType, [Type])
551 dataConSig (MkData {dcUnivTyVars = univ_tvs, dcExTyVars = ex_tvs, dcEqSpec = eq_spec,
552 dcTheta = theta, dcOrigArgTys = arg_tys, dcTyCon = tycon})
553 = (univ_tvs ++ ex_tvs, eqSpecPreds eq_spec ++ theta, arg_tys)
555 dataConFullSig :: DataCon
556 -> ([TyVar], [TyVar], [(TyVar,Type)], ThetaType, [Type])
557 dataConFullSig (MkData {dcUnivTyVars = univ_tvs, dcExTyVars = ex_tvs, dcEqSpec = eq_spec,
558 dcTheta = theta, dcOrigArgTys = arg_tys, dcTyCon = tycon})
559 = (univ_tvs, ex_tvs, eq_spec, theta, arg_tys)
561 dataConStupidTheta :: DataCon -> ThetaType
562 dataConStupidTheta dc = dcStupidTheta dc
564 dataConResTys :: DataCon -> [Type]
565 dataConResTys dc = [substTyVar env tv | tv <- dcUnivTyVars dc]
567 env = mkTopTvSubst (dcEqSpec dc)
569 dataConUserType :: DataCon -> Type
570 -- The user-declared type of the data constructor
571 -- in the nice-to-read form
572 -- T :: forall a. a -> T [a]
574 -- T :: forall b. forall a. (a=[b]) => a -> T b
575 dataConUserType (MkData { dcUnivTyVars = univ_tvs,
576 dcExTyVars = ex_tvs, dcEqSpec = eq_spec,
577 dcTheta = theta, dcOrigArgTys = arg_tys,
579 = mkForAllTys ((univ_tvs `minusList` map fst eq_spec) ++ ex_tvs) $
580 mkFunTys (mkPredTys theta) $
582 mkTyConApp tycon (map (substTyVar subst) univ_tvs)
584 subst = mkTopTvSubst eq_spec
586 dataConInstArgTys :: DataCon
587 -> [Type] -- Instantiated at these types
588 -- NB: these INCLUDE the existentially quantified arg types
589 -> [Type] -- Needs arguments of these types
590 -- NB: these INCLUDE the existentially quantified dict args
591 -- but EXCLUDE the data-decl context which is discarded
592 -- It's all post-flattening etc; this is a representation type
593 dataConInstArgTys (MkData {dcRepArgTys = arg_tys,
594 dcUnivTyVars = univ_tvs,
595 dcExTyVars = ex_tvs}) inst_tys
596 = ASSERT( length tyvars == length inst_tys )
597 map (substTyWith tyvars inst_tys) arg_tys
599 tyvars = univ_tvs ++ ex_tvs
602 -- And the same deal for the original arg tys
603 dataConInstOrigArgTys :: DataCon -> [Type] -> [Type]
604 dataConInstOrigArgTys dc@(MkData {dcOrigArgTys = arg_tys,
605 dcUnivTyVars = univ_tvs,
606 dcExTyVars = ex_tvs}) inst_tys
607 = ASSERT2( length tyvars == length inst_tys, ptext SLIT("dataConInstOrigArgTys") <+> ppr dc <+> ppr inst_tys )
608 map (substTyWith tyvars inst_tys) arg_tys
610 tyvars = univ_tvs ++ ex_tvs
613 These two functions get the real argument types of the constructor,
614 without substituting for any type variables.
616 dataConOrigArgTys returns the arg types of the wrapper, excluding all dictionary args.
618 dataConRepArgTys retuns the arg types of the worker, including all dictionaries, and
619 after any flattening has been done.
622 dataConOrigArgTys :: DataCon -> [Type]
623 dataConOrigArgTys dc = dcOrigArgTys dc
625 dataConRepArgTys :: DataCon -> [Type]
626 dataConRepArgTys dc = dcRepArgTys dc
631 isTupleCon :: DataCon -> Bool
632 isTupleCon (MkData {dcTyCon = tc}) = isTupleTyCon tc
634 isUnboxedTupleCon :: DataCon -> Bool
635 isUnboxedTupleCon (MkData {dcTyCon = tc}) = isUnboxedTupleTyCon tc
637 isVanillaDataCon :: DataCon -> Bool
638 isVanillaDataCon dc = dcVanilla dc
643 classDataCon :: Class -> DataCon
644 classDataCon clas = case tyConDataCons (classTyCon clas) of
645 (dict_constr:no_more) -> ASSERT( null no_more ) dict_constr
648 %************************************************************************
650 \subsection{Splitting products}
652 %************************************************************************
655 splitProductType_maybe
656 :: Type -- A product type, perhaps
657 -> Maybe (TyCon, -- The type constructor
658 [Type], -- Type args of the tycon
659 DataCon, -- The data constructor
660 [Type]) -- Its *representation* arg types
662 -- Returns (Just ...) for any
663 -- concrete (i.e. constructors visible)
664 -- single-constructor
665 -- not existentially quantified
666 -- type whether a data type or a new type
668 -- Rejecing existentials is conservative. Maybe some things
669 -- could be made to work with them, but I'm not going to sweat
670 -- it through till someone finds it's important.
672 splitProductType_maybe ty
673 = case splitTyConApp_maybe ty of
675 | isProductTyCon tycon -- Includes check for non-existential,
676 -- and for constructors visible
677 -> Just (tycon, ty_args, data_con, dataConInstArgTys data_con ty_args)
679 data_con = head (tyConDataCons tycon)
682 splitProductType str ty
683 = case splitProductType_maybe ty of
685 Nothing -> pprPanic (str ++ ": not a product") (pprType ty)
688 deepSplitProductType_maybe ty
689 = do { (res@(tycon, tycon_args, _, _)) <- splitProductType_maybe ty
691 | isNewTyCon tycon && not (isRecursiveTyCon tycon)
692 = deepSplitProductType_maybe (newTyConInstRhs tycon tycon_args)
693 | isNewTyCon tycon = Nothing -- cannot unbox through recursive newtypes
694 | otherwise = Just res}
698 deepSplitProductType str ty
699 = case deepSplitProductType_maybe ty of
701 Nothing -> pprPanic (str ++ ": not a product") (pprType ty)
703 computeRep :: [StrictnessMark] -- Original arg strictness
704 -> [Type] -- and types
705 -> ([StrictnessMark], -- Representation arg strictness
708 computeRep stricts tys
709 = unzip $ concat $ zipWithEqual "computeRep" unbox stricts tys
711 unbox NotMarkedStrict ty = [(NotMarkedStrict, ty)]
712 unbox MarkedStrict ty = [(MarkedStrict, ty)]
713 unbox MarkedUnboxed ty = zipEqual "computeRep" (dataConRepStrictness arg_dc) arg_tys
715 (tycon, tycon_args, arg_dc, arg_tys)
716 = deepSplitProductType "unbox_strict_arg_ty" ty