-getIdArity :: Id -> ArityInfo
-getIdArity (Id _ _ _ _ _ id_info) = getInfo id_info
-
-dataConArity :: DataCon -> Int
-dataConArity id@(Id _ _ _ _ _ id_info)
- = ASSERT(isDataCon id)
- case (arityMaybe (getInfo id_info)) of
- Nothing -> pprPanic "dataConArity:Nothing:" (pprId PprDebug id)
- Just i -> i
-
-addIdArity :: Id -> Int -> Id
-addIdArity (Id u n ty details pinfo info) arity
- = Id u n ty details pinfo (info `addInfo` (mkArityInfo arity))
-\end{code}
-
-%************************************************************************
-%* *
-\subsection[constructor-funs]{@DataCon@-related functions (incl.~tuples)}
-%* *
-%************************************************************************
-
-\begin{code}
-mkDataCon :: Name
- -> [StrictnessMark] -> [FieldLabel]
- -> [TyVar] -> ThetaType -> [TauType] -> TyCon
---ToDo: -> SpecEnv
- -> Id
- -- can get the tag and all the pieces of the type from the Type
-
-mkDataCon n stricts fields tvs ctxt args_tys tycon
- = ASSERT(length stricts == length args_tys)
- data_con
- where
- -- NB: data_con self-recursion; should be OK as tags are not
- -- looked at until late in the game.
- data_con
- = Id (nameUnique n)
- n
- type_of_constructor
- (DataConId data_con_tag stricts fields tvs ctxt args_tys tycon)
- NoPragmaInfo
- datacon_info
-
- data_con_tag = position_within fIRST_TAG data_con_family
-
- data_con_family = tyConDataCons tycon
-
- position_within :: Int -> [Id] -> Int
-
- position_within acc (c:cs)
- = if c == data_con then acc else position_within (acc+1) cs
-#ifdef DEBUG
- position_within acc []
- = panic "mkDataCon: con not found in family"
-#endif
-
- type_of_constructor
- = mkSigmaTy tvs ctxt
- (mkFunTys args_tys (applyTyCon tycon (mkTyVarTys tvs)))
-
- datacon_info = noIdInfo `addInfo_UF` unfolding
- `addInfo` mkArityInfo arity
---ToDo: `addInfo` specenv
-
- arity = length args_tys
-
- unfolding
- = noInfo_UF
-{- LATER:
- = -- if arity == 0
- -- then noIdInfo
- -- else -- do some business...
- let
- (tyvars, dict_vars, vars) = mk_uf_bits tvs ctxt args_tys tycon
- tyvar_tys = mkTyVarTys tyvars
- in
- case (Con data_con tyvar_tys [VarArg v | v <- vars]) of { plain_Con ->
-
- mkUnfolding EssentialUnfolding -- for data constructors
- (mkLam tyvars (dict_vars ++ vars) plain_Con)
- }
-
- mk_uf_bits tvs ctxt arg_tys tycon
- = let
- (inst_env, tyvars, tyvar_tys)
- = instantiateTyVarTemplates tvs
- (map uniqueOf tvs)
- in
- -- the "context" and "arg_tys" have TyVarTemplates in them, so
- -- we instantiate those types to have the right TyVars in them
- -- instead.
- case (map (instantiateTauTy inst_env) (map ctxt_ty ctxt))
- of { inst_dict_tys ->
- case (map (instantiateTauTy inst_env) arg_tys) of { inst_arg_tys ->
-
- -- We can only have **ONE** call to mkTemplateLocals here;
- -- otherwise, we get two blobs of locals w/ mixed-up Uniques
- -- (Mega-Sigh) [ToDo]
- case (mkTemplateLocals (inst_dict_tys ++ inst_arg_tys)) of { all_vars ->
-
- case (splitAt (length ctxt) all_vars) of { (dict_vars, vars) ->
-
- (tyvars, dict_vars, vars)
- }}}}
- where
- -- these are really dubious Types, but they are only to make the
- -- binders for the lambdas for tossed-away dicts.
- ctxt_ty (clas, ty) = mkDictTy clas ty
--}
-\end{code}
-
-\begin{code}
-mkTupleCon :: Arity -> Id
-
-mkTupleCon arity
- = Id unique n ty (TupleConId arity) NoPragmaInfo tuplecon_info
- where
- n = mkTupleDataConName arity
- unique = uniqueOf n
- ty = mkSigmaTy tyvars []
- (mkFunTys tyvar_tys (applyTyCon tycon tyvar_tys))
- tycon = mkTupleTyCon arity
- tyvars = take arity alphaTyVars
- tyvar_tys = mkTyVarTys tyvars
-
- tuplecon_info
- = noIdInfo `addInfo_UF` unfolding
- `addInfo` mkArityInfo arity
---LATER:? `addInfo` panic "Id:mkTupleCon:pcGenerateTupleSpecs arity ty"
-
- unfolding
- = noInfo_UF
-{- LATER:
- = -- if arity == 0
- -- then noIdInfo
- -- else -- do some business...
- let
- (tyvars, dict_vars, vars) = mk_uf_bits arity
- tyvar_tys = mkTyVarTys tyvars
- in
- case (Con data_con tyvar_tys [VarArg v | v <- vars]) of { plain_Con ->
- mkUnfolding
- EssentialUnfolding -- data constructors
- (mkLam tyvars (dict_vars ++ vars) plain_Con) }
-
- mk_uf_bits arity
- = case (mkTemplateLocals tyvar_tys) of { vars ->
- (tyvars, [], vars) }
- where
- tyvar_tmpls = take arity alphaTyVars
- (_, tyvars, tyvar_tys) = instantiateTyVarTemplates tyvar_tmpls (map uniqueOf tyvar_tmpls)
--}
-
-fIRST_TAG :: ConTag
-fIRST_TAG = 1 -- Tags allocated from here for real constructors
-\end{code}
-
-\begin{code}
-dataConTag :: DataCon -> ConTag -- will panic if not a DataCon
-dataConTag (Id _ _ _ (DataConId tag _ _ _ _ _ _) _ _) = tag
-dataConTag (Id _ _ _ (TupleConId _) _ _) = fIRST_TAG
-dataConTag (Id _ _ _ (SpecId unspec _ _) _ _) = dataConTag unspec
-
-dataConTyCon :: DataCon -> TyCon -- will panic if not a DataCon
-dataConTyCon (Id _ _ _ (DataConId _ _ _ _ _ _ tycon) _ _) = tycon
-dataConTyCon (Id _ _ _ (TupleConId a) _ _) = mkTupleTyCon a
-
-dataConSig :: DataCon -> ([TyVar], ThetaType, [TauType], TyCon)
- -- will panic if not a DataCon
-
-dataConSig (Id _ _ _ (DataConId _ _ _ tyvars theta_ty arg_tys tycon) _ _)
- = (tyvars, theta_ty, arg_tys, tycon)
-
-dataConSig (Id _ _ _ (TupleConId arity) _ _)
- = (tyvars, [], tyvar_tys, mkTupleTyCon arity)
- where
- tyvars = take arity alphaTyVars
- tyvar_tys = mkTyVarTys tyvars
-
-dataConFieldLabels :: DataCon -> [FieldLabel]
-dataConFieldLabels (Id _ _ _ (DataConId _ _ fields _ _ _ _) _ _) = fields
-dataConFieldLabels (Id _ _ _ (TupleConId _) _ _) = []
-
-dataConStrictMarks :: DataCon -> [StrictnessMark]
-dataConStrictMarks (Id _ _ _ (DataConId _ stricts _ _ _ _ _) _ _) = stricts
-dataConStrictMarks (Id _ _ _ (TupleConId arity) _ _)
- = nOfThem arity NotMarkedStrict
-
-dataConArgTys :: DataCon
- -> [Type] -- Instantiated at these types
- -> [Type] -- Needs arguments of these types
-dataConArgTys con_id inst_tys
- = map (instantiateTy tenv) arg_tys
- where
- (tyvars, _, arg_tys, _) = dataConSig con_id
- tenv = zipEqual "dataConArgTys" tyvars inst_tys
-\end{code}
-
-\begin{code}
-mkRecordSelId field_label selector_ty
- = Id (nameUnique name)
- name
- selector_ty
- (RecordSelId field_label)
- NoPragmaInfo
- noIdInfo
- where
- name = fieldLabelName field_label
-