cmpId_withSpecDataCon,
externallyVisibleId,
idHasNoFreeTyVars,
- idWantsToBeINLINEd, getInlinePragma,
+ idWantsToBeINLINEd, getInlinePragma,
idMustBeINLINEd, idMustNotBeINLINEd,
isBottomingId,
isConstMethodId,
isConstMethodId_maybe,
- isDataCon,
+ isDataCon, isAlgCon, isNewCon,
isDefaultMethodId,
isDefaultMethodId_maybe,
isDictFunId,
addIdDemandInfo,
addIdStrictness,
addIdUpdateInfo,
+ addIdDeforestInfo,
getIdArity,
getIdDemandInfo,
getIdInfo,
getIdUnfolding,
getIdUpdateInfo,
getPragmaInfo,
- replaceIdInfo,
+ replaceIdInfo, replacePragmaInfo,
addInlinePragma, nukeNoInlinePragma, addNoInlinePragma,
-- IdEnvs AND IdSets
import Class ( classOpString, SYN_IE(Class), GenClass, SYN_IE(ClassOp), GenClassOp )
import IdInfo
import Maybes ( maybeToBool )
-import Name {- ( nameUnique, mkLocalName, mkSysLocalName, isLocalName,
+import Name ( nameUnique, mkLocalName, mkSysLocalName, isLocalName,
mkCompoundName, mkInstDeclName,
isLocallyDefinedName, occNameString, modAndOcc,
isLocallyDefined, changeUnique, isWiredInName,
nameString, getOccString, setNameVisibility,
isExported, ExportFlag(..), DefnInfo, Provenance,
- OccName(..), Name
- ) -}
+ OccName(..), Name, SYN_IE(Module),
+ NamedThing(..)
+ )
import PrelMods ( pREL_TUP, pREL_BASE )
import Lex ( mkTupNameStr )
import FieldLabel ( fieldLabelName, FieldLabel(..){-instances-} )
nmbrType, nmbrTyVar,
GenType, GenTyVar
)
-import PprStyle
import Pretty
import MatchEnv ( MatchEnv )
import SrcLoc --( mkBuiltinSrcLoc )
incrUnique,
Unique{-instance Ord3-}
)
-import Outputable ( ifPprDebug, Outputable(..) )
+import Outputable ( ifPprDebug, Outputable(..), PprStyle(..) )
import Util {- ( mapAccumL, nOfThem, zipEqual, assoc,
panic, panic#, pprPanic, assertPanic
) -}
---------------- Data constructors
- | DataConId ConTag
+ | AlgConId -- Used for both data and newtype constructors.
+ -- You can tell the difference by looking at the TyCon
+ ConTag
[StrictnessMark] -- Strict args; length = arity
[FieldLabel] -- Field labels for this constructor;
--length = 0 (not a record) or arity
\begin{description}
%----------------------------------------------------------------------
-\item[@DataConId@:] For the data constructors declared by a @data@
+\item[@AlgConId@:] For the data constructors declared by a @data@
declaration. Their type is kept in {\em two} forms---as a regular
@Type@ (in the usual place), and also in its constituent pieces (in
the ``details''). We are frequently interested in those pieces.
%************************************************************************
\begin{code}
-isDataCon (Id _ _ _ (DataConId _ __ _ _ _ _ _ _) _ _) = True
-isDataCon (Id _ _ _ (TupleConId _) _ _) = True
-isDataCon (Id _ _ _ (SpecId unspec _ _) _ _) = isDataCon unspec
-isDataCon other = False
+-- isDataCon returns False for @newtype@ constructors
+isDataCon (Id _ _ _ (AlgConId _ _ _ _ _ _ _ _ tc) _ _) = isDataTyCon tc
+isDataCon (Id _ _ _ (TupleConId _) _ _) = True
+isDataCon (Id _ _ _ (SpecId unspec _ _) _ _) = isDataCon unspec
+isDataCon other = False
+
+isNewCon (Id _ _ _ (AlgConId _ _ _ _ _ _ _ _ tc) _ _) = isNewTyCon tc
+isNewCon other = False
+
+-- isAlgCon returns True for @data@ or @newtype@ constructors
+isAlgCon (Id _ _ _ (AlgConId _ _ _ _ _ _ _ _ _) _ _) = True
+isAlgCon (Id _ _ _ (TupleConId _) _ _) = True
+isAlgCon (Id _ _ _ (SpecId unspec _ _) _ _) = isAlgCon unspec
+isAlgCon other = False
isTupleCon (Id _ _ _ (TupleConId _) _ _) = True
isTupleCon (Id _ _ _ (SpecId unspec _ _) _ _) = isTupleCon unspec
isTupleCon other = False
-
-{-LATER:
-isSpecId_maybe (Id _ _ _ (SpecId unspec ty_maybes _) _ _)
- = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
- Just (unspec, ty_maybes)
-isSpecId_maybe other_id
- = Nothing
-
-isSpecPragmaId_maybe (Id _ _ _ (SpecPragmaId specid _) _ _)
- = Just specid
-isSpecPragmaId_maybe other_id
- = Nothing
--}
\end{code}
@toplevelishId@ tells whether an @Id@ {\em may} be defined in a nested
toplevelishId (Id _ _ _ details _ _)
= chk details
where
- chk (DataConId _ __ _ _ _ _ _ _) = True
+ chk (AlgConId _ __ _ _ _ _ _ _) = True
chk (TupleConId _) = True
chk (RecordSelId _) = True
chk ImportedId = True
idHasNoFreeTyVars (Id _ _ _ details _ info)
= chk details
where
- chk (DataConId _ _ _ _ _ _ _ _ _) = True
+ chk (AlgConId _ _ _ _ _ _ _ _ _) = True
chk (TupleConId _) = True
chk (RecordSelId _) = True
chk ImportedId = True
-- remember that all type and class decls appear in the interface file.
-- The dfun id must *not* be omitted, because it carries version info for
-- the instance decl
- (DataConId _ _ _ _ _ _ _ _ _) -> True
+ (AlgConId _ _ _ _ _ _ _ _ _) -> True
(TupleConId _) -> True
(RecordSelId _) -> True
(SuperDictSelId _ _) -> True
getPragmaInfo (Id _ _ _ _ info _) = info
replaceIdInfo :: Id -> IdInfo -> Id
-
replaceIdInfo (Id u n ty details pinfo _) info = Id u n ty details pinfo info
-{-LATER:
-selectIdInfoForSpecId :: Id -> IdInfo
-selectIdInfoForSpecId unspec
- = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
- noIdInfo `addUnfoldInfo` getIdUnfolding unspec
--}
+replacePragmaInfo :: Id -> PragmaInfo -> Id
+replacePragmaInfo (Id u sn ty details _ info) prag = Id u sn ty details prag info
\end{code}
%************************************************************************
\begin{code}
getIdArity :: Id -> ArityInfo
getIdArity id@(Id _ _ _ _ _ id_info)
- = --ASSERT( not (isDataCon id))
- arityInfo id_info
+ = arityInfo id_info
addIdArity :: Id -> ArityInfo -> Id
addIdArity (Id u n ty details pinfo info) arity
%************************************************************************
%* *
+\subsection[Id-arities]{Deforestation related functions}
+%* *
+%************************************************************************
+
+\begin{code}
+addIdDeforestInfo :: Id -> DeforestInfo -> Id
+addIdDeforestInfo (Id u n ty details pinfo info) def_info
+ = Id u n ty details pinfo (info `addDeforestInfo` def_info)
+\end{code}
+
+%************************************************************************
+%* *
\subsection[constructor-funs]{@DataCon@-related functions (incl.~tuples)}
%* *
%************************************************************************
= Id (nameUnique n)
n
data_con_ty
- (DataConId data_con_tag stricts fields tvs ctxt con_tvs con_ctxt args_tys tycon)
+ (AlgConId data_con_tag stricts fields tvs ctxt con_tvs con_ctxt args_tys tycon)
IWantToBeINLINEd -- Always inline constructors if possible
noIdInfo
\begin{code}
dataConTag :: DataCon -> ConTag -- will panic if not a DataCon
-dataConTag (Id _ _ _ (DataConId tag _ _ _ _ _ _ _ _) _ _) = tag
+dataConTag (Id _ _ _ (AlgConId 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 _ _ _ (AlgConId _ _ _ _ _ _ _ _ tycon) _ _) = tycon
dataConTyCon (Id _ _ _ (TupleConId a) _ _) = tupleTyCon a
dataConSig :: DataCon -> ([TyVar], ThetaType, [TyVar], ThetaType, [TauType], TyCon)
-- will panic if not a DataCon
-dataConSig (Id _ _ _ (DataConId _ _ _ tyvars theta con_tyvars con_theta arg_tys tycon) _ _)
+dataConSig (Id _ _ _ (AlgConId _ _ _ tyvars theta con_tyvars con_theta arg_tys tycon) _ _)
= (tyvars, theta, con_tyvars, con_theta, arg_tys, tycon)
dataConSig (Id _ _ _ (TupleConId arity) _ _)
(tyvars, theta, tau) = splitSigmaTy (idType con)
dataConFieldLabels :: DataCon -> [FieldLabel]
-dataConFieldLabels (Id _ _ _ (DataConId _ _ fields _ _ _ _ _ _) _ _) = fields
+dataConFieldLabels (Id _ _ _ (AlgConId _ _ fields _ _ _ _ _ _) _ _) = fields
dataConFieldLabels (Id _ _ _ (TupleConId _) _ _) = []
dataConStrictMarks :: DataCon -> [StrictnessMark]
-dataConStrictMarks (Id _ _ _ (DataConId _ stricts _ _ _ _ _ _ _) _ _) = stricts
+dataConStrictMarks (Id _ _ _ (AlgConId _ stricts _ _ _ _ _ _ _) _ _) = stricts
dataConStrictMarks (Id _ _ _ (TupleConId arity) _ _)
= nOfThem arity NotMarkedStrict
nmbrDataCon id@(Id _ _ _ (TupleConId _) _ _) nenv
= (nenv, id) -- nothing to do for tuples
-nmbrDataCon id@(Id u n ty (DataConId tag marks fields tvs theta con_tvs con_theta arg_tys tc) prag info)
+nmbrDataCon id@(Id u n ty (AlgConId tag marks fields tvs theta con_tvs con_theta arg_tys tc) prag info)
nenv@(NmbrEnv ui ut uu idenv tvenv uvenv)
= case (lookupUFM_Directly idenv u) of
Just xx -> trace "nmbrDataCon: in env???\n" (nenv, xx)
(nenv2, new_fields) = (mapNmbr nmbrField fields) nenv
(nenv3, new_arg_tys) = (mapNmbr nmbrType arg_tys) nenv2
- new_det = DataConId tag marks new_fields (bottom "tvs") (bottom "theta") (bottom "tvs") (bottom "theta") new_arg_tys tc
+ new_det = AlgConId tag marks new_fields (bottom "tvs") (bottom "theta") (bottom "tvs") (bottom "theta") new_arg_tys tc
new_id = Id u n (bottom "ty") new_det prag info
in
(nenv3, new_id)
------------
nmbr_details :: IdDetails -> NmbrM IdDetails
-nmbr_details (DataConId tag marks fields tvs theta con_tvs con_theta arg_tys tc)
+nmbr_details (AlgConId tag marks fields tvs theta con_tvs con_theta arg_tys tc)
= mapNmbr nmbrTyVar tvs `thenNmbr` \ new_tvs ->
mapNmbr nmbrTyVar con_tvs `thenNmbr` \ new_con_tvs ->
mapNmbr nmbrField fields `thenNmbr` \ new_fields ->
mapNmbr nmbr_theta theta `thenNmbr` \ new_theta ->
mapNmbr nmbr_theta con_theta `thenNmbr` \ new_con_theta ->
mapNmbr nmbrType arg_tys `thenNmbr` \ new_arg_tys ->
- returnNmbr (DataConId tag marks new_fields new_tvs new_theta new_con_tvs new_con_theta new_arg_tys tc)
+ returnNmbr (AlgConId tag marks new_fields new_tvs new_theta new_con_tvs new_con_theta new_arg_tys tc)
where
nmbr_theta (c,t)
= --nmbrClass c `thenNmbr` \ new_c ->